Decorating Jasmine's it method
sebald opened this issue · 5 comments
When using global.<method>
to decorate Jasmine's public API nothing is returned. Usually Jasmine returns the spec object, as you can see in its source code.
Using jasmine.getEnv().it('test blabla', () => {})
will correctly return the spec object, but decorating this will mess up Protractor as mentioned by @juliemr in angular/protractor#2823
I am not quite sure what's the issue here. I checked the source of jasminewd
and found that wrapInControlFlow
does not return something, but I thought decorating the global.it
would add my function before jasminewd
decorates the tests.
For context: I want to add additional properties (SRS reference, custom identifier) to the spec object, so that I can create a report with information about SRS coverage etc.
Something like this:
// In the test suite
it('SRS_ID_1', 'should test something', () => {
expect(true).toBeTruthy();
});
// Decorator
var originalIt = global.it;
global.it = function (ref, desc, fn) {
var spec = originalIt(desc, fn);
spec.result.ref = ref;
return spec;
}
// Reporter
var results = [];
jasmine.getEnv().addReporter({
specDone: (result) => { results.push(result) },
jasmineDone () => {
// Create report
}
});
I tried something. I do not thing that it's the correct way, but it works :-x
sebald@b1a712a#diff-168726dbe96b3ce427e7fedce31bb0bc
wrapInControlFlow
returns the result of the globalFn
which is the jasminewd
wrapper for Jasmine's spec methods (it
, fit
, ...).
Using the code from my last comment I can now add additional properties to the spec.result
and display/use it in reporter.
@sebald I think that that commit is actually doing the right thing. Jasminewd should wrap the functions before your code, so it needs to pass along the returned value. Can you make that into a PR?
Of course. I add a test for it tomorrow and make a PR.
Now that I've merged in an equivalent PR is this safe to close?
Tested it today. Works fine for me :)
Thanks!