Reputation: 2719
I'm getting the above error when I want to mock http REST services created using Restangular. Here's my piece of code:
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 anybody encountered the same issue.And any fix ?
Upvotes: 3
Views: 24551
Reputation: 84
It seems to me that you should rather invoke spyOn inside function passed to "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);
});
Upvotes: 0
Reputation: 532
This is how I did it, hope it helps.
var Restangular;
beforeEach(inject(function( _Restangular_) {
Restangular = _Restangular_;
spyOn(Restangular, 'all').and.callThrough();
}));
Upvotes: 2