jeudi 27 août 2015

How to reuse angular javascript unit test modules?

I'm new to angular js, trying to write unit test for a function with experiment flags (defined in the build file) on and off respectively, in two different files.

In the first file:

describe('MyController', function(){
    var x = var_x;
    beforeEach(...);
    describe('TestFun', function (){
        it('should be **true** when flag is on', function(){
            expect(TestFun(x).toBe(**true**);
        });
    });
});

In the second file:

describe('MyController', function(){
    var x = var_x;
    beforeEach(...);
    describe('TestFun', function (){
        it('should be **false** when flag is off', function(){
            expect(TestFun(x).toBe(**false**);
        });
    });
});

The test can pass, however, there is a lot of duplication in these two files. Is there a fancier way to write these two tests without these duplications? Thanks!

Aucun commentaire:

Enregistrer un commentaire