Reputation: 17173
I'm new to jasmine spies.
Here is my test:
spyOn(gapi, 'ready').andCallThrough();
inject(function(_endpointService_) {
endpointService = _endpointService_;
});
var _doSteps = gapi.ready.mostRecentCall.args[0];
var wrapper = {_doSteps: _doSteps};
spyOn(wrapper, '_doSteps');
gapi.ready(); //calls _doSteps through promise in service.
//_doSteps();
expect(wrapper._doSteps).wasCalled(); //gives error - not called.
as in my endpointService I have:
gapi.ready($endpointService._doSteps);
return $endpointService;
and my _doSteps method:
_doSteps: function(){
console.log('in dosteps!');
},
it logs 'in dosteps!' before the spy complains that _doSteps wasn't called. How do I do this?
Upvotes: 1
Views: 511
Reputation: 22824
Your spyOn() function returns a spy object - so I'me not sure why you are using mostRecentCall and the wrapper ?
var gapi = new Gapi(); // must create a variable to spy on.
var readySpy = spyOn(gapi, 'ready').andCallThrough();
// .. something that calls gapi.ready here
expect(readySpy).toHaveBeenCalled();
Upvotes: 1