so i have 6 karma jasmine tests, in one file i have 3, which im testing all my factories
the test file for the factory is as followed
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 showing executed 4 of 6
PhantomJS 1.9.8 (Mac OS X 0.0.0): Executed 4 of 6 SUCCESS (0.004 secs / 0.029 secs)
So for some reason after the first it 'it' in the factory test file its skipping over the other two, even though there is no failures and all are contained in a beforeEach
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!!!!
});
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With