How can I make jasmine.js stop after a test failure?

自作多情 提交于 2019-12-22 04:01:06

问题


I want the runner to stop after the first failure rather than running all the tests.


回答1:


It's a hack, but you can do this by inserting this script before your first test;

<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>

Jasmine's latest commit at the time of applying this was https://github.com/pivotal/jasmine/commit/8b02bf731b193e135ccb486e99b3ecd7165bf95c




回答2:


This is a very popular feature request for the jasmine project: https://github.com/jasmine/jasmine/issues/414

It looks like there is interest in implementing it, but it has also been open for a very long time, so who knows when it might be released. Alternatively, Mocha implements this feature with its -b/--bail option: https://mochajs.org/#usage. Its api is very similar to Jasmine's so you may want to consider making the switch.



来源:https://stackoverflow.com/questions/14679951/how-can-i-make-jasmine-js-stop-after-a-test-failure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!