我正在关注有关异步支持的 Jasmine 1.3 文档,并且在使示例正常工作时遇到问题。
我spec/async-spec.js
使用的(略有修改的(源代码如下:
describe("Asynchronous specs", function() {
var value, flag;
it("should support async execution of test preparation and expectations", function() {
runs(function() {
flag = false;
value = 0;
console.log("HERE");
setTimeout(function() {
console.log("HERE2");
flag = true;
}, 750);
});
waitsFor(function() {
value++;
return flag;
}, "The Value should be incremented", 5000);
runs(function() {
expect(value).toBeGreaterThan(0);
});
});
});
我正在使用以下命令运行它:
atom --test --timeout 60 spec/async-spec.js
它给出以下结果:
HERE
F
Asynchronous specs
it should support async execution of test preparation and expectations
timeout: timed out after 5000 msec waiting for The Value should be incremented
Finished in 5.746 seconds
1 test, 1 assertion, 1 failure, 0 skipped
我希望测试同时返回HERE
和HERE2
,并且断言通过,唉,事实并非如此。
atom --version
详细信息是:
Atom : 1.38.2
Electron: 2.0.18
Chrome : 61.0.3163.100
Node : 8.9.3
确切的茉莉花版本是:1.3.1 revision 1354556913
我对原子/茉莉花测试相当陌生,所以任何帮助将不胜感激。
这不是一个理想的解决方案,因为出于一些原因,我希望继续使用默认的Jasmine版本,但我发现安装以下软件包使我能够获得更好的异步支持:
https://www.npmjs.com/package/atom-jasmine2-test-runner
然后我可以参考 Jasmine 2.9 文档并正确实现它们:
https://jasmine.github.io/2.9/introduction