javascript - 我如何检查 after block 中是否有任何 mocha 测试失败?

标签 javascript testing mocha.js

describe('some tests', function () {
  /*
   * Run some tests...
   */
})

after(function () {
  failures = ? // <--- what goes here?
  console.log(failures + " tests failed!")
})

如果测试失败,我会用它来保持 chromedriver 的浏览器打开,并返回到 report success or failure to sauce labs .

Mocha 的运行者和记者 have the info I'm looking for作为 stats 但我不确定如何从测试文件中获取它们。

最佳答案

我找到了这个问题的答案 here

afterEach(function() {
  if (this.currentTest.state == 'failed') {
    // ...
  }
});

关于javascript - 我如何检查 after block 中是否有任何 mocha 测试失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22031765/

相关文章:

javascript - 我想使用用户脚本捕获tinymce编辑器中的键盘事件(即添加键盘快捷键)

javascript - 如何编辑安全 cookie?

asp.net-mvc - 在 MVC6 中处理 IActionResult

c# - 代码覆盖率是否包含在 Visual Studio Team Services (Visual Studio Online) 包中

javascript - 使用 Karma 和 Mocha 进行异步测试

javascript - 将数组元素传递给 settimeout 函数

javascript - ASP.Net 应用程序中的可嵌入小部件

perl - 使用 Dist::Zilla 构建 perl 模块时提示用户选项

angularjs - 如何使用 Sinon 测试在 promise 中设置的 AngularJS Controller 值

javascript - 使用 nyc 运行 mocha 时指定 mocha.opts 的位置?