I\'m using the Jasmine BDD Javascript library and really enjoying it. I have test code that I\'d like to reuse (for example, testing multiple implementations of a base clas
Let me summarize it with working example
describe('test', function () {
beforeEach(function () {
this.shared = 1;
});
it('should test shared', function () {
expect(this.shared).toBe(1);
});
testShared();
});
function testShared() {
it('should test in function', function() {
expect(this.shared).toBe(1);
});
}
The crucial parts here are this keyword to pass context and because of this we have to use "normal" functions (another crucial part).
For production code I would probably use normal function only in beforeEach to pass/extract context but keep to use arrow-function in specs for brevity.
Passing context as parameter wouldn't work because normally we define context in beforeEach block wich invoked after.
Having describe section seems not important, but still welcome for better structure