Testing Jasmine in separate files without breaking the describe?

Asked

Viewed 51 times

2

I want to organize my javascript tests in separate files, but these can be part of a common module. For example:

describe("Controllers", function () {

    describe('Move list Controller', function () {

        //ListController its
    });

    describe('Movie Detail Controller', function () {

        describe('must activate with', function () {
             //details controller its when activates
        });
        //other details controller's its

    });

    describe('Reserve Controller', function () {
         // reserve controller its
    });
});

I have the describe('Controllers'), and under it all controllers. But here you can see the proportion that the files will take because each controller will have several its. What I need is to break these tests into a file by controller, but still keeping them as part of describe('controllers')

I tried to call the same describe in different files and it generated redundancy:

inserir a descrição da imagem aqui

Any idea how separate into files without breaking the describe?

1 answer

1


You can do it like this:

var parte = ['descrição', fnction(){ /* os it's aqui */ }]; // podes importar de outros arquivos

and then inside each describe inside the describe('Controllers' flames these other describe with .apply()

describe.apply(null, parte );

Example: http://jsfiddle.net/cttb6zzb/

var A = ['Parte A', function () {

    it('shoud pass the test A1', function () {
        expect(1).toEqual(1);
    });
    it('should pass the test A2', function () {
        expect(2).toEqual(2);
    });
}];
var B = ['Parte B', function () {

    it('shoud pass the test B1', function () {
        expect('b1').toEqual('b1');
    });
    it('should pass the test B2', function () {
        expect('b2').toEqual('b2');
    });
}];

describe('Controllers', function () {
    describe.apply(null, A);
    describe.apply(null, B);
});
  • 1

    It worked, so I separated a file describe.apply.js just to do that. Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.