我正在尝试创建一个带有逻辑的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)