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
forgottofly
source
to share
2 answers
This is how I did it, hope it helps.
var Restangular;
beforeEach(inject(function( _Restangular_) {
Restangular = _Restangular_;
spyOn(Restangular, 'all').and.callThrough();
}));
+2
Ivan Toncev
source
to share
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
user3498393
source
to share