【发布时间】:2015-01-07 20:31:14
【问题描述】:
我正在尝试使用 Jasmine 2 的新 done() 回调来测试异步设置的值。
我的测试基于 Jasmine 在他们的文档 (http://jasmine.github.io/2.0/upgrading.html#section-Asynchronous_Specs) 中给出的示例:
it('can set a flag after a delay', function(done) {
var flag = false,
setFlag = function() {
//set the flag after a delay
setTimeout(function() {
flag = true;
done();
}, 100);
};
setFlag();
expect(flag).toBe(true);
});
我得到的结果是“Expected false to be true”,所以我猜测在检查标志值之前它没有等待调用 done() 回调。
有谁知道为什么这个测试失败了?
谢谢!
【问题讨论】:
标签: javascript unit-testing jasmine jasmine2.0