Node.js茉莉助手onComplete

时间:2018-07-27 10:05:12

标签: node.js jasmine

我想设置一个在jasmine完成所有任务之后运行的回调。

这是我尝试过的:

package.json

{
  "scripts": {
    "test": "jasmine"
  }
  ...
     "jasmine": "^2.8.0"
}

spec / support / jasmine.json

{
  "helpers": [
    "helpers/env.js",
    "helpers/**/*.js"
  ],
  ...
}

spec / helpers / env.js

jasmine.onComplete( () => console.log('yay, done') )

但要不断出错

$ npm test
...
jasmine.onComplete( () => console.log('yay, done') )
    ^
TypeError: jasmine.onComplete is not a function
...

1 个答案:

答案 0 :(得分:1)

看来,

您不会初始化Jasmine。

var Jasmine = require('jasmine');
var jasmine = new Jasmine();

引用this

然后这应该起作用:

jasmine.onComplete(function(passed) {
  if(passed) {
    console.log('All specs have passed');
  }
  else {
    console.log('At least one spec has failed');
  }
});