相关疑难解决方法(0)

从Mocha中的afterEach挂钩中检测测试失败

我正在尝试创建一个带有逻辑的afterEach挂钩,只有在前一次测试失败时才会触发.例如:

it("some_test1", function(){
  // something that could fail
})

it("some_test2", function(){
  // something that could fail
})

afterEach(function(){
  if (some_test_failed) {
    // do something to respond to the failing test
  } else {
    // do nothing and continue to next test
  }
})
Run Code Online (Sandbox Code Playgroud)

但是,我没有办法在afterEach钩子中检测测试是否失败.是否有某种事件监听器我可以附加到摩卡?也许是这样的:

myTests.on("error", function(){ /* ... */ })
Run Code Online (Sandbox Code Playgroud)

javascript mocha.js node.js

25
推荐指数
1
解决办法
5950
查看次数

标签 统计

javascript ×1

mocha.js ×1

node.js ×1