S
S
Sergey Nikolaev2015-08-05 14:38:34
JavaScript
Sergey Nikolaev, 2015-08-05 14:38:34

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')
        });
    });

2. How to create and use a global constant - an array containing mock sets?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sanex3339, 2015-08-05
@sanex3339

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 question

Ask a Question

731 491 924 answers to any question