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
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.
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.
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.
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!
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();
});
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With