2013-02-04 26 views
9

我希望跑步者在第一次失败后停止,而不是运行所有测试。如何在测试失败后停止jasmine.js?

+5

是什么让这个“不是一个真正的问题”? –

+0

这里有一个公开的问题https://github.com/jasmine/jasmine/issues/414。作者写了一个插件https://github.com/goodeggs/jasmine-bail-fast。在我的AngularJS单元测试中,我不存在'this.results()'(由karma运行)。 –

回答

5

这是一个破解,但你可以通过在第一次测试之前插入这个脚本来做到这一点;

<script type="text/javascript"> 
// after every test has run 
afterEach(function() { 
    // check if any have failed 
    if(this.results_.failedCount > 0) { 
    // if so, change the function which should move to the next test 
    jasmine.Queue.prototype.next_ = function() { 
     // to instead skip to the end 
     this.onComplete(); 
    } 
    } 
}); 
</script> 

茉莉的最新提交的申请,这是https://github.com/pivotal/jasmine/commit/8b02bf731b193e135ccb486e99b3ecd7165bf95c

+0

'console.log(this.results_)'打印“undefined” –

+0

是的,茉莉花v2已经出来,因为这是在2013年发布 –

+0

也许删除了投票? –

0

这是茉莉项目非常受欢迎的功能要求的时间: https://github.com/jasmine/jasmine/issues/414

它看起来像有正在执行之中的兴趣,但它已经开放很长一段时间了,所以谁知道它什么时候会被释放。或者,Mocha使用-b/- bail选项来实现此功能:https://mochajs.org/#usage。它的API与Jasmine非常相似,所以你可能想考虑制作这个开关。

相关问题