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
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
Share Improve this question edited May 22, 2015 at 6:28 captainsac 2,4903 gold badges29 silver badges51 bronze badges asked May 22, 2015 at 6:10 Siva KumarSiva Kumar 7251 gold badge7 silver badges21 bronze badges 2- Unfortunately what you are asking for is currently not possible, although its more of a limitation of javascript rather than jasmine. In that there is no way for a function to be declared across several files. – Mark Broadhurst Commented Aug 4, 2015 at 14:25
- What version of Jasmine are you running? – Adam Commented Feb 17, 2016 at 20:41
2 Answers
Reset to default 4My 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.