Angularjs 为什么httpbackend不能在angular中工作?
我正在尝试使用$httpBackend测试$HttpWebService?我在这方面犯了一个错误。如何使用$httpbackend测试服务 这是我的密码 试试这个Angularjs 为什么httpbackend不能在angular中工作?,angularjs,angularjs-directive,angularjs-scope,jasmine,angular-ui-router,Angularjs,Angularjs Directive,Angularjs Scope,Jasmine,Angular Ui Router,我正在尝试使用$httpBackend测试$HttpWebService?我在这方面犯了一个错误。如何使用$httpbackend测试服务 这是我的密码 试试这个 authRequestHandler = httpBackend.when('GET', 'data.json') .respond([{ "name": "hello" }, { "name": "hello12" }, { "name": "hello22" }, { "name"
authRequestHandler = httpBackend.when('GET', 'data.json')
.respond([{
"name": "hello"
}, {
"name": "hello12"
}, {
"name": "hello22"
}, {
"name": "hello45"
}]);
service.callData().then(function(response) {
console.log(response)
expect(response.data.length).toBe(4)
})
httpBackend.flush();
您还没有告诉它期待GET请求。你需要告诉它期待一个
authRequestHandler = httpBackend.when('GET', 'data.json')
.respond([{
"name": "hello"
}, {
"name": "hello12"
}, {
"name": "hello22"
}, {
"name": "hello45"
}]);
service.callData().then(function(response) {
console.log(response)
expect(response.data.length).toBe(4)
})
httpBackend.flush();