如何在测试失败后让jasmine.js停止?

dav*_*sit 9 javascript tdd jasmine

我希望跑步者在第一次失败后停止而不是运行所有测试.

Jam*_*son 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>
Run Code Online (Sandbox Code Playgroud)

Jasmine在申请时的最新提交是https://github.com/pivotal/jasmine/commit/8b02bf731b193e135ccb486e99b3ecd7165bf95c