Answer the question
In order to leave comments, you need to log in
Where can I find good Jasmine testing practices?
Where can I find good Jasmine testing practices?
In general, 2 questions are tormenting:
1. Get rid of repetitions
This code at the beginning of each test is the same
var $compile, $rootScope, $httpBackend;
beforeEach(function(){
module('app');
inject(function($injector){
$compile = $injector.get('$compile');
$rootScope = $injector.get('$rootScope');
$httpBackend = $injector.get('$httpBackend')
});
});
Answer the question
In order to leave comments, you need to log in
You have this code inside describe, which is probably also inside another describe, so shove this code into beforeEach of the parent describe, so this code will be common for all tests, and shove the code unique for each test into beforeEach describe' ov, inside of which there are already directly tests (it)
let classVar;
describe(('class test') => {
beforeEach(() = > {
classVar = new Blablabla;
});
describe(('method test') => {
let methodVar;
beforeEach(() = > {
methodVar = classVar.init();
});
describe(('test 1') => {
let testVar;
beforeEach(() = > {
testVar = methodVar.getValue();
});
it(('should be equal 1') => {
expect(testVar).equal(1);
});
});
});
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question