javascript - 如何使用 Jasmine 1.3.1 和 Atom 进行异步测试
问题描述
我正在关注有关异步支持的 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
andHERE2
并且断言通过,但事实并非如此。
atom --version
详情如下:
Atom : 1.38.2
Electron: 2.0.18
Chrome : 61.0.3163.100
Node : 8.9.3
确切的茉莉花版本是:1.3.1 revision 1354556913
我对 Atom/Jasmine 测试相当陌生,因此将不胜感激任何帮助。
解决方案
这不是一个理想的解决方案,因为出于几个原因我想继续使用默认的 Jasmine 版本,但我发现安装以下软件包使我能够获得更好的异步支持:
https://www.npmjs.com/package/atom-jasmine2-test-runner
然后我可以参考 Jasmine 2.9 文档并正确实现它们:
推荐阅读
- pandas - 屏蔽数据集以使 Xarray 中的维度相同(使用 where 函数)
- bash - 要从 Deep Archive/Glacier 检索的 AWS 文件列表
- sql - 在 SQL 中加入最近的日期
- python - 如何在没有扩展名的目录中打印文件?PYTHON
- kubernetes - 在 k8s PersistentVolume 清单文件下定义 claimRef 时命名空间是强制性的吗?
- python - 正则表达式替换多个“AND NOT”条件
- c++ - C++ 编译和链接问题
- json - 没有使用 RestTemplate 获得外部 Json API 响应
- reactjs - NextJS 动态导入问题
- python - 用户关闭应用程序时调用函数( pyQt5 )