Reputation: 14581
How does a BDD-style (mocha, jasmine, etc.) large wrapped single describe()
get broken down into multiple files. I have a 5,000-line unit test file, all of it wrapped as follows:
describe('services',function(){
describe('serviceA',function(){...});
describe('serviceB',function(){...});
describe('serviceC',function(){...});
describe('serviceD',function(){...});
// .....
describe('serviceN',function(){...});
});`
For sanity's sake I would like to break each one ('serviceA','serviceB',...,'serviceN') into its own file. But I want each to still be inside describe("services")
.
I see 2 methods:
describe('serviceA',require('./services/serviceA'));
(repeat lots of times)I don't like the second method, since it requires a lot of keeping of file name, require()
and describe()
in sync (and thus violates DRY).
I prefer each file know what it is testing, and not have to explicitly add the path, rather just have the testrunner intelligently include everything in './services'
, and thus have inside serviceA.js
:
describe('serviceA', function() {
// ....
});
but then I need some way to "wrap" 'serviceA' inside 'services'. Is there any way to do that?
In this case, I am testing an angular app via karma, but the concept is the same.
Upvotes: 2
Views: 870
Reputation: 6940
Jasmine's describe
has no special meaning for loading of files. It's a descriptor. What's stopping you from just doing this?
Karma config:
files: [
'src/services/**/*.js',
'tests/services/**/*.js'
]
serviceA.spec.js
describe('services', function () {
describe('serviceA', function () {
});
});
serviceB.spec.js
describe('services', function () {
describe('serviceB', function () {
});
});
Upvotes: 1