我知道如何在 mocha 的 afterEach()
方法中检查测试是否失败:这里有解释:detecting test failures from within afterEach hooks in Mocha
但是那些使用 suite
和 test
(tdd) 而不是 describe
和 it
的人呢?
如何在此处检查当前测试是否失败?相同的代码将无法工作,因为 state
将是未定义的:
teardown(async () => {
// check if failed:
if (this.currentTest.state === 'failed') {
console.log("fail");
}
});
最佳答案
似乎它与 tdd 的工作方式有点不同(使用 suite
和 test
)。
访问 this.ctx.currentTest
而不是 this.currentTest
对我有用。
示例:
if (this.ctx.currentTest.state === 'failed') {
console.log(`'${this.ctx.currentTest.title}' failed`);
}
关于javascript - 如果当前测试失败,如何检查mocha(tdd)的拆解方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58661128/