我正在尝试使用$ httpBackend测试$ http webservice?我收到了一个错误。如何使用$ httpbackend测试服务?
这是我的代码 http://plnkr.co/edit/S3LFymv8hrxtatWaCv1A?p=preview
it('call http service', function() {
authRequestHandler = httpBackend.when('GET', 'data.json')
.respond([{
"name": "hello"
}, {
"name": "hello12"
}, {
"name": "hello22"
}, {
"name": "hello45"
}]);
httpBackend.flush();
service.callData().then(function(response) {
console.log(response)
expect(response.data.length).toBe(4)
})
})
答案 0 :(得分:0)
试试这个
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();