0

我知道如何在afterEach()mocha 的方法中检查测试是否失败:这里解释了:从 Mocha 中的 afterEach 挂钩中检测测试失败

但是那些使用suiteand test(tdd) 而不是describeand的人呢it

如何检查当前测试是否在此处失败?state由于未定义,相同的代码将不起作用:

  teardown(async () => {
    // check if failed:
    if (this.currentTest.state === 'failed') {
      console.log("fail");
    }
  });
4

1 回答 1

0

suite似乎它与 tdd (使用and )有点不同test

访问this.ctx.currentTest而不是this.currentTest为我工作。

例子:

if (this.ctx.currentTest.state === 'failed') {
  console.log(`'${this.ctx.currentTest.title}' failed`);
}
于 2019-11-01T14:42:21.317 回答