ngMockE2E导致每个请求模拟添加到依赖项的时刻

时间:2015-06-18 05:06:28

标签: angularjs angular-mock ngmocke2e

我有

angular.module("myModule", [
 //Some dependency
 "ngMockE2E"
])

这实际上是模拟模板请求和抛出错误

Unexpected request: GET javascripts/custom/utils/templates/global_loader.html
No more request expected
    at $httpBackend (angular-mocks.js?e_a_v=5:1226)
    at sendReq (angular.js?e_a_v=5:10215)
    at $get.serverRequest (angular.js?e_a_v=5:9927)
    at processQueue (angular.js?e_a_v=5:14437)
    at angular.js?e_a_v=5:14453
    at Scope.$get.Scope.$eval (angular.js?e_a_v=5:15702)
    at Scope.$get.Scope.$digest (angular.js?e_a_v=5:15513)
    at Scope.$get.Scope.$apply (angular.js?e_a_v=5:15807)
    at bootstrapApply (angular.js?e_a_v=5:1628)
    at Object.invoke (angular.js?e_a_v=5:4426)

如果我注释掉ngMockE2E,它可以正常工作。 知道我做错了吗?

1 个答案:

答案 0 :(得分:2)

ngMockE2E引入$httpBackend所以是的,所有HTTP请求都被模拟。要允许加载模板,请将其添加到模块

.run(function($httpBackend) {
    // pass through template requests
    $httpBackend.whenGET(/\.html$/).passThrough();
});