SpyOn gives method no error exists

I run the Karma test in an angular application, in the test I have the following:

return inject(function($injector) { this.Service = { functionWithPromise: function(postdata){ var deferred = $q.defer(); deferred.resolve({ data: {} }); return deferred.promise; } }; }; 

and

 it('should call the functionWithPromise function when the create function is called', function() { res = {} this.scope.create(res); this.scope.$digest(); spyOn(Service, "functionWithPromise"); expect(this.Service.functionWithPromise).toHaveBeenCalled(); }); 

when I run the test, it gives this error:

 functionWithPromise() method does not exist 

How can I get a test to recognize the functionWithPromise () function?

+5
source share
1 answer

It this.Service out I needed to spy on this.Service instead of a service, for example:

 spyOn(this.Service, "functionWithPromise"); 
+4
source

All Articles