我如何检查 after 块中是否有任何 mocha 测试失败? [英] How might I check if any mocha tests failed from within an after block?

查看:60
本文介绍了我如何检查 after 块中是否有任何 mocha 测试失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

如果测试失败,我会使用它来保持 chromedriver 的浏览器打开,并向酱汁实验室报告成功或失败.

I'd use this to keep chromedriver's browser open if a test failed, and to report success or failure to sauce labs.

Mocha 的跑步者和记者 有我的信息寻找作为stats,但我不确定如何从测试文件中获取它们.

Mocha's Runner and Reporters have the info I'm looking for as stats but I'm not sure how to get to them from within a test file.

推荐答案

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

I found answer to this question here

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

这篇关于我如何检查 after 块中是否有任何 mocha 测试失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆