如何使用 grunt-contrib-jasmine 配置随机选项?我可以直接使用 jasmine 的命令行来执行此操作,但通过 grunt-cli 运行 jasmine 的任务时我没有找到随机选项。然后命令行的输出始终显示规范的随机输出。
示例更新:
以下是 Jasmine 的 json:
{
// Spec directory path relative to the current working dir when jasmine is executed.
"spec_dir": "spec",
// Array of filepaths (and globs) relative to spec_dir to include and exclude
"spec_files": [
"**/*[sS]pec.js"
],
// Array of filepaths (and globs) relative to spec_dir to include before jasmine specs
"helpers": [
"helpers/**/*.js"
],
// Stop execution of a spec after the first expectation failure in it
stopSpecOnExpectationFailure: false,
// This is the random option I need on gruntfile
random: false
}
以下是 gruntfile json:
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json')
,jasmine : {
myapp : {
src : ['src/**/*.js']
,options : {
specs : 'spec/**/*{s,S}pec.js'
}
}
}
});
...
答案1
我找到了问题的答案。至少我已经测试过了,它有效。在每个描述声明的顶部,您可以配置 Suit Test 的随机选项。可以使用以下语句:
describe('My suite', function(){
jasmine.getEnv().configure({random:false});
// There are several tests here...
afterAll(function(){
jasmine.getEnv().configure({random:true});
});
...