$ httpBackend.whenGET(some url).passThrough()抛出异常?

时间:2013-02-07 13:09:56

标签: javascript angularjs

我在这里遇到了一些问题。我试图模拟我的一些http请求到服务器并传递其中一些!当我调用passThrougth()时会抛出一个错误!

Error: Unexpected request: GET view/networks.html
No more request expected
    at Error (<anonymous>)
    at $httpBackend (http://localhost:8080/js/lib/angular-mocks.js:887:9)
    at $httpBackend (http://localhost:8080/js/lib/angular-mocks.js:880:11)
    at sendReq (http://localhost:8080/js/lib/angular-scenario.js:18264:9)
    at $http (http://localhost:8080/js/lib/angular-scenario.js:18055:17)
    at Function.$get.$http.(anonymous function) [as get] (http://localhost:8080/js/lib/angular-scenario.js:18198:18)
    at $get.$q.when.then.then.next.locals (http://localhost:8080/js/lib/angular-scenario.js:16605:34)
    at deferred.promise.then.wrappedCallback (http://localhost:8080/js/lib/angular-scenario.js:16028:59)
    at deferred.promise.then.wrappedCallback (http://localhost:8080/js/lib/angular-scenario.js:16028:59)
    at ref.then (http://localhost:8080/js/lib/angular-scenario.js:16065:26)  

这是我的跑步

myAppDev.run(function ($httpBackend) {
    $httpBackend.whenGET("view/networks.html").passThrough();
    $httpBackend.whenGET('/r/networkInterface').respond(networkInterfaces);

});

我的配置有什么问题?

任何方式,当我调用响应(“有一些响应”)时,我得到正确的结果。即$ httpBackEnd返回响应的内容!

1 个答案:

答案 0 :(得分:1)

好的家伙,经过漫长而艰苦的斗争,这个问题很难解决。

1-更新到angularJS 1.0.5

2-在我的测试中我有这行代码

myAppDev.config(function ($provide) {
    $provide.decorator('$httpBackend', angular.mock.e2e.$httpBackendDecorator);
}); 

当我删除这行代码时,一切都很完美。然而,这就是Vojta jina使用的in this fiddle.