【问题标题】:Mocha and NightmareJS- continue testMocha 和 NightmareJS- 继续测试
【发布时间】:2016-10-27 17:38:36
【问题描述】:

我遇到了一个简单的问题,我有大约 5 个测试要属于一个组,其中一个我强制它们失败,但我无法退出失败状态:

.goto(url)
.wait('#element')
.evaluate(fnc...)
wait('#newelement')
....
evaluate(function(){
 return document.querySlector('#myid').innerText
})
.then(function(result) {
result.should.equal('1');// I know I am expecting 2
done();
})
// will never be executed.
.then.....

// 抛出以下消息。 错误:超过 15000 毫秒的超时。确保在此测试中调用了 done() 回调。

没关系,但是在此测试失败后我需要进行其他测试,但我似乎无法继续或有一种优雅的方式来报告失败而不影响其余测试。

【问题讨论】:

    标签: javascript node.js mocha.js chai nightmare


    【解决方案1】:

    如果你想强制测试失败,你可以调用 done 传递一个错误作为参数:

    done(new Error('this is my error message'))
    

    所以在你的情况下,是这样的:

    .goto(url)
    .wait('#element')
    .evaluate(fnc...)
    wait('#newelement')
    ....
    evaluate(function(){
     return document.querySlector('#myid').innerText
    })
    .then(function(result) {
    done(new Error('Please test, fail because I want you to.'));
    })
    // will never be executed.
    .then.....
    

    另外,作为旁注,您的原始代码可能无法正常工作,因为在同一个链调用中多次调用evaluate,请参阅this 答案以获取更多详细信息。

    【讨论】:

      猜你喜欢
      • 2021-05-28
      • 1970-01-01
      • 2016-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多