Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 234
davidadsit Avatar asked Feb 04 '13 03:02

davidadsit


People also ask

How do I ignore Jasmine test?

Excluding Tests / Specs If you want to exclude a specific test, simply use xit() instead of it() . The x means exclude. describe('description', function () { xit('description', function () {}); }); If you want to exclude an entire describe block, use xdescribe() instead of describe() .

What is done () in Jasmine?

If the function passed to Jasmine takes an argument (traditionally called done ), Jasmine will pass a function to be invoked when asynchronous work has been completed.

How do you throw a Jasmine error?

var throwMeAnError = function() { //throw new Error(); }; describe("Different Methods of Expect Block",function() { var exp = 25; it("Hey this will throw an Error ", function() { expect(throwMeAnError). toThrow(); }); }); As can be seen, we have commented that line from where our method was throwing the exception.

Does Jasmine run tests in parallel?

Jasmine doesn't actually support parallel execution. It runs one spec (or before/after) function at a time.


1 Answers

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

like image 194
Jamie Mason Avatar answered Oct 25 '22 04:10

Jamie Mason