Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 973
Siva Kumar Avatar asked May 22 '15 06:05

Siva Kumar


People also ask

How to run a specific test suite in Jasmine?

And there’s a simple solution: By using fdescribe instead of describe, Jasmine will only run that particular test suite. By using fit instead of it, Jasmine will run only that particular spec.

Why use Jasmine for automated testing?

It provides utilities that can be used to run automated tests for both synchronous and asynchronous code. Jasmine has many features such as: It’s fast and has low overhead and no external dependencies.

How do I change the default location for Jasmine testing?

If you don’t use the default location for the jasmine.json configuration file, you simply need to specify the custom location via the jasmine --config option. You can find more CLI options from the official docs. In this section we’ll learn about the basic elements of Jasmine testing such as suites, specs, expectations, matchers and spies, etc.

What is the difference between fdescribe and fit in Jasmine?

By using fdescribe instead of describe, Jasmine will only run that particular test suite. By using fit instead of it, Jasmine will run only that particular spec. So here you go. If you need to run a single suite/spec, you can quickly do so by using fdescribe and fit. But beware!


2 Answers

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();
});
like image 52
Adam Avatar answered Oct 12 '22 14:10

Adam


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.

like image 45
Subash Avatar answered Oct 12 '22 15:10

Subash