Siva Kumar
Siva Kumar

Reputation: 725

How to group test suites in jasmine when tests exists in different files?

As per documentation, we can have groups-sub groups of test suites, but they exists only in one file like below

describe('Main Group - Module 1', function () {

    beforeEach(function () {
        module('app');
    });

    describe('sub group - 1', function () { // Sub group        
        // specs goes here
    });

     describe('sub group - 2', function () { // Sub group       
        // specs goes here
    });
});

If I want to keep sub group -1 & sub group -2 in two different files, how can I group these two subgroups in Main Group - Module?

Thanks

Upvotes: 7

Views: 6924

Answers (2)

Adam
Adam

Reputation: 2077

My use case for this is Jasmine-Node, so the require statements don't make any difference for me. If you're doing browser-based Jasmine, you'll have to use RequireJS for this solution. Alternatively, without require statements, you can use this example from the Jasmine repo issues.

file1.js

module.exports = function() {
    describe('sub group - 1', function () { // Sub group        
        // specs goes here
    });
};

file2.js

module.exports = function() {
    describe('sub group - 2', function () { // Sub group        
        // specs goes here
    });
};

file3.js

var subgroup1 = require( './file1.js' );
var subgroup2 = require( './file2.js' );

describe('Main Group - Module 1', function () {

    beforeEach(function () {
        module('app');
    });

    subgroup1();
    subgroup2();
});

Upvotes: 4

Subash
Subash

Reputation: 7266

You can do the following:

file1.js

describe('Main Group - Module 1', function () {

    beforeEach(function () {
        module('app');
    });

    describe('sub group - 1', function () { // Sub group        
        // specs goes here
    });

});

file2.js

describe('Main Group - Module 1', function () {

    beforeEach(function () {
        module('app');
    });

     describe('sub group - 2', function () { // Sub group       
        // specs goes here
    });
});

Notice the same parent name.

Upvotes: 3

Related Questions