I'm using a decorator for Angular service $httpBackend to change the urls of all http calls:
app.config(function($provide) {
$provide.decorator('$httpBackend', function($delegate) {
return function(method, url, post, callback, headers, timeout, withCredentials, responseType) {
url = changeUrl(url);
$delegate(method, url, post, callback, headers, timeout, withCredentials, responseType);
};
})
});
In some Jasmine tests I need to mock the $httpBackend service:
describe('...', function() {
beforeEach(module('...'));
beforeEach(inject(function($injector) {
$httpBackend = $injector.get('$httpBackend');
$httpBackend.when('GET', '...').respond(function(method, url) {
return ...
});
}));
}
Now I'm getting error "$httpBackend.when is not a function" when executing these tests.
Any idea how to fix this? I'd prefer a solution without having test specific code in my app config.