Hi,
I am trying to write an implementation to allow extending spies as per this issue:
However I am having an issue reading my ENV config in the createSpy phase in base.js
I looked over the custom matchers implementation and decided to implement it in a similar way, that is storing the custom spy functions in ENV and in a spec specific manner.
However I am having a problem when I try to read the saved functions in the createSpy function as it says I am not inside a spec or in a before function, which I am when creating the spy in the test.
The issue is that currentRunnable() does not return any result.
The offending function being called from the createSpy function is this:
this.getSpyExtensions = function() {
if(!currentRunnable()) {
throw new Error('Spy extensions must be fetched in a before function or a spec');
}
return runnableResources[currentRunnable().id].spyExtensions;
};
I am trying to call this function from createSpy function like this:
j$.getEnv().getSpyExtensions();
And the self test for it:
it("allows adding a custom function to spies", function(done) {
env.it('spec defining a custom spy function', function() {
env.addSpyExtensions({
returnMock: function() {
return 'mock';
}
});
var returnMockSpy = j$.createSpy("returnMockSpy");
env.expect(returnMockSpy.and.returnMock).toBeDefined();
env.expect(returnMockSpy.and.returnMock()).toEqual('mock');
});
var specExpectations = function(result) {
expect(result.status).toEqual('passed');
};
env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute();
});
What am I doing wrong?
Should I store the spy functions in a different place?
Am I testing this incorrectly?
I will appreciate if someone could explain why the create spy function thinks it is not called inside a spec, is there a lifecycle i am not aware of?
Thanks