简体   繁体   English

Mocha.js测试保释(假)不适用于beforeEach

[英]Mocha.js tests bail(false) do not work for beforeEach

When I try to start my mocha test with bail(false) I need to not stop tests even if some beforeEach hook gives an error. 当我尝试使用bail(false)启动我的mocha测试bail(false) ,即使某些beforeEach挂钩出错,我也不需要停止测试。

But this doesn't help, did someobody coped with this earlier? 但这没有帮助,有人提前应对了吗? Or.. is it possible? 或者......有可能吗?

In order for your tests to continue running even when the beforeEach() throws an error, you have to handle that error. 为了使测试继续运行,即使beforeEach()抛出错误,您也必须处理该错误。 Currently, beforeEach() is throwing an error which is unhandled. 目前,beforeEach()抛出一个未处理的错误。

To handle this error in NodeJS, use a callback with a parameter: 要在NodeJS中处理此错误,请使用带参数的回调:

beforeEach(done) {
    // your code here

    // if there was an error
    if (error !== null) {
        // callback with a parameter, indicates failure
        done(new Error('failed'));
    } else {
        // more code here
        // callback without parameter, indicates success!
        done();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM