我正在尝试使用ngMock模拟请求/响应,并得到此错误:Unexpected request: GET /locales/en_us.json
。在挖掘之后,我发现了这篇关于如何绕过错误的文章。添加$translateProvider.preferredLanguage('en_us')
修复了错误,但模板没有渲染,即,我只看到一个空白页。在run方法中,我有以下内容:
$httpBackend.whenGET(env.baseUri + '/1.0/test-data').respond(function(method, url, data){
return [200, [
{
"id": 1,
"name": "test name",7,
"version": "1.0"
}
]]
在config方法中:
$translateProvider.preferredLanguage('en_us');
我通过为"locale"添加passThrough修复了这个错误:
myAppDev = angular.module('myAppDev', ['myApp', 'ngMockE2E']);
myAppDev.run(function($httpBackend) {
phones = [{name: 'phone1'}, {name: 'phone2'}];
// adds a new phone to the phones array
$httpBackend.whenPOST('/phones').respond(function(method, url, data) {
var phone = angular.fromJson(data);
phones.push(phone);
return [200, phone, {}];
});
$httpBackend.whenGET(/^/locales//).passThrough();
});
修复方法是添加$httpBackend.whenGET(/^/locale//).passThrough();看到上面。