&引用$httpBackend.when不是函数;在Jasmine测试中模拟AngularJS$httpBackend并使用装饰器时出错

&引用$httpBackend.when不是函数;在Jasmine测试中模拟AngularJS$httpBackend并使用装饰器时出错,angularjs,jasmine,decorator,angular-http,angular-http-interceptors,Angularjs,Jasmine,Decorator,Angular Http,Angular Http Interceptors,我正在使用Angular service$httpBackend的装饰程序来更改所有http调用的URL: app.config(function($provide) { $provide.decorator('$httpBackend', function($delegate) { return function(method, url, post, callback, headers, timeout, withCredentials, responseType) {

我正在使用Angular service$httpBackend的装饰程序来更改所有http调用的URL:

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);
      };
   })
});
在一些Jasmine测试中,我需要模拟$httpBackend服务:

describe('...', function() {
    beforeEach(module('...'));
    beforeEach(inject(function($injector) {
        $httpBackend = $injector.get('$httpBackend');
        $httpBackend.when('GET', '...').respond(function(method, url) {
            return ...
        });
    }));
}
现在我在执行这些测试时遇到错误“$httpBackend.when不是函数”


你知道怎么解决这个问题吗?我更喜欢在我的应用程序配置中没有测试特定代码的解决方案

您只需在特定模块中定义decorator,而不用在测试中加载该模块


除了装饰httpBackend,您还可以使用http拦截器。在测试中加载它会导致相同的问题(但如果愿意,您仍然可以使用相同的技术来避免在测试中加载它)。

在特定模块中定义装饰器,而不要在测试中加载该模块。这很简单;)只要把你的评论抄下来,我就接受你的回答。德克萨斯州!举个例子。我仍然收到一个错误我有同样的问题-什么意思定义一个特定模块中的装饰,而不加载在您的测试模块?你能举一个简单的例子来说明这一点吗?我发现了一个指向另一个堆栈溢出的用户链接,它帮助我理解了如何拥有两个独立的模块,并将它们加载到一个组合模块中: