I started using Jasmine to test, angularjs, but soon I started wondering which of the approach is good, and why ? I chose the single expect per spec. I liked it because a non-techie can understand it better, well, that is the point of BDD ,is not it ? For example
describe('Testing multple expect per spec My Service', function() {
beforeEach(/* some stuff*/);
it('test part ',function(){
expect('part 1').toBe('part one'); //
expect('part 2').toBe('part two'); // some crazy stuff, just for example
}
}
describe('Testing single expect per spec My Service', function() {
beforeEach(/* some stuff*/);
it('test part one ',function(){
expect('part 1').toBe('part one'); // just for example
}
it('test part two ',function(){
expect('part 2').toBe('part two'); // just for example
}
}
But soon got into trouble, I realized that the beforeEach is actually reseting/ creating a new object of my service ( not shown in the above example) thus the encapsulated behavior is not reflecting correctly.
For example, I am testing the firstMethod() part of a injected service which changes a data structure of the service, 'test part one', then in the second spec i am testing the secondMethod() which tests the change data structure in the 'test part two'. But due to the fact that beforeEach re-injected my service, the 'test part two' fails. How can I get around such situation ?
Please help Jasmine newbie here.