根据文档,我们可以拥有组 - 子组的测试套件,但它们只存在于一个文件中,如下所示
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
});
});
如果我想保留子组-1 & 子组-2 在两个不同的文件中,如何将这两个子组分组到主组 - 模块?
由于
答案 0 :(得分:3)
您可以执行以下操作:
<强> 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
});
});
请注意相同的父名称。
答案 1 :(得分:3)
我的用例是Jasmine-Node,因此require
语句对我没有任何影响。如果您正在使用基于浏览器的Jasmine,则必须使用RequireJS来获得此解决方案。或者,如果没有require语句,您可以使用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();
});