Jasmine 2.6 中的异步测试
Async Test in Jasmine 2.6
自 2.x 以来,异步测试的语法已更改,并且 documentation 不明确。
有人可以阐明我如何执行某些代码,阻塞 3 秒,然后 运行 使用新语法的测试条件吗?
it('should update the table when new data is provided', function() {
var newData = ",0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23\nX-Y,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1";
fixture.datum(csv).call(fp);
expect(fp.dataset()).toEqual(csv);
fp.dataset(newData);
expect(fp.dataset()).toEqual(newData);
//block for 3 seconds
expect(fixture.selectAll(".row").nodes().length).toBe(3);
});
done 需要作为参数传递给 spec,done() 需要作为最后一条语句调用setTimeout() 块。
如果异步规范总共超过 5 秒,它将失败,请参阅 jasmine 文档摘录以获取更多信息:
By default jasmine will wait for 5 seconds for an asynchronous spec to finish before causing a timeout failure. If the timeout expires before done is called, the current spec will be marked as failed and suite execution will continue as if done was called.
If specific specs should fail faster or need more time this can be adjusted >by passing a timeout value to it, etc.
it('should update the table when new data is provided', function(done) {
var newData = ",0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23\nX-Y,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1";
fixture.datum(csv).call(fp);
expect(fp.dataset()).toEqual(csv);
fp.dataset(newData);
expect(fp.dataset()).toEqual(newData);
//block for 3 seconds, then execute expect
setTimeout(function() {
expect(fixture.selectAll(".row").nodes().length).toBe(3);
done(); //dont forget!!
}, 3000);
});
自 2.x 以来,异步测试的语法已更改,并且 documentation 不明确。
有人可以阐明我如何执行某些代码,阻塞 3 秒,然后 运行 使用新语法的测试条件吗?
it('should update the table when new data is provided', function() {
var newData = ",0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23\nX-Y,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1";
fixture.datum(csv).call(fp);
expect(fp.dataset()).toEqual(csv);
fp.dataset(newData);
expect(fp.dataset()).toEqual(newData);
//block for 3 seconds
expect(fixture.selectAll(".row").nodes().length).toBe(3);
});
done 需要作为参数传递给 spec,done() 需要作为最后一条语句调用setTimeout() 块。
如果异步规范总共超过 5 秒,它将失败,请参阅 jasmine 文档摘录以获取更多信息:
By default jasmine will wait for 5 seconds for an asynchronous spec to finish before causing a timeout failure. If the timeout expires before done is called, the current spec will be marked as failed and suite execution will continue as if done was called.
If specific specs should fail faster or need more time this can be adjusted >by passing a timeout value to it, etc.
it('should update the table when new data is provided', function(done) {
var newData = ",0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23\nX-Y,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1";
fixture.datum(csv).call(fp);
expect(fp.dataset()).toEqual(csv);
fp.dataset(newData);
expect(fp.dataset()).toEqual(newData);
//block for 3 seconds, then execute expect
setTimeout(function() {
expect(fixture.selectAll(".row").nodes().length).toBe(3);
done(); //dont forget!!
}, 3000);
});