如何使用grunt-contrib-jasmine配置随机选项?我可以直接使用jasmine的命令行来完成,但是通过grunt cli运行jasmine的任务,我没有找到随机选项。然后,命令行的输出总是显示规范的随机输出。
发布于 2019-01-18 02:41:37
我找到了我问题的答案。至少我已经测试过了,它起作用了。在每个describe声明的顶部,您可以配置Suit Test的随机选项。它可以使用以下语句:
describe('My suite', function(){
jasmine.getEnv().configure({random:false});
// There are several tests here...
afterAll(function(){
jasmine.getEnv().configure({random:true});
});
...发布于 2019-12-07 21:26:26
如果你使用jasmine.d.ts并且你的测试是用typescript编写的,你也可以在jasmine.d.ts的环境接口中添加如下函数:
interface Env {
// some code
// add function:
configure(b: any): void;
}然后在你的测试中,你可以写下这样的代码:
/// <reference path="../../../../typings/jasmine/jasmine.d.ts" />
jasmine.getEnv().configure({ random: false });我测试了这种方法,最后,我不必在每个describe函数中将random选项设置为false。我在引用路径之后添加了它,它对所有测试都有效。
编辑:您还可以将jasmine配置作为单独的文件包含在grunt-contrib-jasmine任务的options/helpers部分中。类似于:
jasmine: {
src: [some source files],
options: {
specs: [some spec files],
helpers: 'helpers.js'
}
}https://stackoverflow.com/questions/54204111
复制相似问题