gpt4 book ai didi

AngularJS $httpBackend - "No more request expected"错误

转载 作者:行者123 更新时间:2023-12-03 22:20:20 25 4
gpt4 key购买 nike

好像this是显示如何使用 $httpBacked 的有效解决方案http://jsfiddle.net/EgMpe/8/

但对于我的情况:

路线

app.config(['$routeProvider', function($routeProvider) { $routeProvider.

when('/', {templateUrl: 'partials/user-list.html'}).

...

伪造服务:
app.run(function($httpBackend) {

var users = [{"id":1,"name":"bob","email":"bob@bobs.com"}, {"id":2,"name":"bob2","email":"bob2@bobs.com"}]

$httpBackend.whenGET('/rest/users').respond(function(method,url,data) {
console.log("Getting users");
return [200, users, {}];
});
});

..

真实服务:
services.factory('Users', function($resource){
return $resource('/rest/users', {}, {
get: {method: 'GET', isArray:true}
});
});

我有 错误 当转到我的“/”路由时,将我重定向到 user-list.html页:

Error: Unexpected request: GET partials/user-list.html No more request expected at $httpBackend .../mysite/public/angular/libs/angular-1.2.0/angular-mocks.js:1060:9)



问题1:是否 httpBackend防止做任何其他事情 http要求?

我尝试使用 直通让http命中真实服务器端的方法:
$httpBackend.whenGET(/^\/mysite\//).passThrough();

但这无济于事。

最佳答案

使用 $httpBackend您必须提前指定要执行的所有请求。也许是来自 Mastering Web Application Development with AngularJS 的简短摘录将阐明原因:

The verifyNoOutstandingExpectation method verifies that all the expected calls were made ($http methods invoked and responses flushed), while the verifyNoOutstandingRequest call makes sure that code under test didn't trigger any unexpected XHR calls. Using those two methods we can make sure that the code under the test invokes all the expected methods and only the expected ones.

关于AngularJS $httpBackend - "No more request expected"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20432482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com