karma jasmine not executing all tests

Further to the accepted answer, which is a much better structure for the tests anyway, I have found reproducible scenario for this: nested beforeEach sections found in a test cause Karma to stop running any further Jasmine tests. You can see in the question that it is indeed the case - the beforeEach's for the injects are within an outer beforeEach.

As part of a merge, one of our beforeEach lines that loads the module under test had been moved within a later beforeEach inadvertently. This was preventing all tests after that one running. Karma was reporting that x of y tests were running where x was 65 less than y, but that the test run was successful and there were none skipped.

So if you encounter this, check your report output for the last 'successfully' execute test (I say successfully in quotes as it's probably the one causing the issue) and see if that doesn't have nested beforeEach's in it.


Well then, let's start here. Change your file to this to clear a few things up and see if it goes away. You also need to define answers in the last test.

describe('Quiz Factories', function() {

  var counter, answerSheet, questions;

  beforeEach( function(){
    module( 'geafApp' );

    inject( function( _counter_, _answer_sheet_, _questions_ ){
      counter = _counter_;
      answerSheet = _answer_sheet_;
      questions = _questions_;
    });
  });

  describe( 'when a question is asked', function(){
    it( 'should return a number', function(){
      expect( counter ).toBeNumber();
    });

    it( 'should return an empty object', function(){
      expect( answerSheet ).toBeEmptyObject();
    });

    it( 'should return an empty object', function(){
      expect( questions ).toHaveObject( answers ); // ??? answers is not defined!!!!
    });
  });
});