SpyOn could not find an object for spying for everyone ()
I am getting the above error when I want to poke fun at http REST services created with Restangular. Here is my code snippet:
var someParameter = [{ "id": 1, "name": "Length" }]
spyOn(Restangular, 'one').and.callThrough();
it('expect company service to be called', function () {
httpBackend.expectGET('http://localhost:8283/com/companies', {
someParameter: someParameter
}).respond(mockToReturn);
});
Has anyone faced the same problem. And any fix?
+3
source to share
2 answers
It seems to me that you should rather call the spyOn function inside the function passed to it by "it"
var someParameter = [{ "id": 1, "name": "Length" }]
it('expect company service to be called', function () {
spyOn(Restangular, 'one').and.callThrough();
httpBackend.expectGET('http://localhost:8283/com/companies', {
someParameter: someParameter
}).respond(mockToReturn);
});
0
source to share