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