Karma jasmine does not complete all tests

so I have 6 tests of jasmine karma, in one file I have 3 that I tested in all my factories

The test file for the factory is as follows

describe('Quiz Factories', function() { beforeEach(function() { //Ensure angular modules available beforeEach(module('geafApp')); beforeEach(inject(function (_counter_) { counter = _counter_; })); beforeEach(inject(function (_answer_sheet_) { answer_sheet = _answer_sheet_; })); beforeEach(inject(function (_questions_) { questions = _questions_; })); }); it('it should return a number', function () { expect(counter).toBeNumber(); }); it('it should return an empty object', function () { expect(answer_sheet).toBeEmptyObject(); }); it('it should return an empty object', function () { expect(questions).toHaveObject(answers); }); }); 

in my console log its execution is 4 of 6

PhantomJS 1.9.8 (Mac OS X 0.0.0): Completed 4 of 6 SUCCESSES (0.004 sec. / 0.029 sec.)

So, for some reason, after the first "it" in the factory test file, it skips the other two, even if there are no failures, and they are all contained in the beforeEach file

+6
source share
3 answers

Ok, then start here. Change your file to this to clear a few things and see if it disappears. You should also determine the 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!!!! }); }); }); 
+3
source

In addition to the accepted answer, which in any case is a much better framework for tests, I found a reproducible script for this: the beforeEach sections nested in beforeEach cause Karma to stop any further Jasmine tests. You can see in the question that this is true - beforeEach for beforeEach is inside the external beforeEach .

As part of the merge, one of our beforeEach lines that loads the module under test was accidentally moved to a later beforeEach . This prevented all tests from running after that. Karma reported that x of y tests were performed, where x was 65 less than y, but that the test run was successful and was not skipped.

Therefore, if you encounter this, check the report output for the last “successfully” completed test (I say “successfully” in quotation marks, since it probably caused the problem), and look, there is no beforeEach in it beforeEach nested.

+7
source

Also relevant:

It may also happen that an exception occurs before the tests turn out to be expect - this will not cause the test to be declared unsuccessful, since it has never been run. This will be shown as a reduced number of running tests. In this case, you can check the console logs for errors.

+1
source

All Articles