Search code examples
javascripttddjasmine

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.


Solution

  • 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