作为Mocha的普通用户,我在AfterEach
回调中有一些清洁方法。
但是我那里还有一些测试,可以断言我的it()
套件中每个describe()
测试的输出
示例:
afterEach(async function () {
1. expect(mytestMethod(), `this is test`).to.equal(true); //test
2. console.log(this.currentTest.title, this.currentTest.state);
3. await clearTargeting(); //Clean-up-after method
}
});
如果第1步失败,则不会执行第3步,但是我仍然需要执行此步骤以清除测试空间以进行下一个测试。
我尝试使用它,但是没有帮助。
if (this.currentTest.state === 'failed') {
await clearTargeting();
} else if (this.currentTest.state === 'passed') {
await clearTargeting();
}
有人做了类似的事情吗?将感谢您的帮助。
更新:已经通过在BeforeEach中移动方法来解决它:-) 但是无论如何,有趣的是,如我最初所问的那样。