Closed Barryrowe closed 8 years ago
If mockService is called with a replacement function in a scenario like below:
var isFirstCall = true; function myReplacementFunc(){ if(isFirstCall){ isFirstCall = false; return {test:"value"}; }else{ return undefined; } } mockService(MyService, { get: myReplacementFunc }
the get function on the mocked service is not spied on properly, and so something like this (using jasmine-sinon):
get
expect(MyService.get).toHaveBeenCalledOnce();
fails with an error like:
Expected spy "function myReplacementFunc() { if (isFirstCall ) { isFirstCall = false; return { test: "value" }; } else { return undefined; } }" to have been called twice. "function myReplacementFunc() { if (isFirstCall ) { isFirstCall = false; return { test: "value" }; } else { return undefined; } }" was called 0 times.
I would have expected this to work the same as if I had just manually wired up the sinon spies like:
sinon.stub(MyService, 'get', myReplacementFunc);
It appears that if line 564 of the current distribution were changed from:
service[key] = value;
to
sinon.stub(service, key, value);
this would work as expected.
This was fixed with the merge above.
If mockService is called with a replacement function in a scenario like below:
the
get
function on the mocked service is not spied on properly, and so something like this (using jasmine-sinon):fails with an error like:
I would have expected this to work the same as if I had just manually wired up the sinon spies like:
It appears that if line 564 of the current distribution were changed from:
to
this would work as expected.