我正试图在业力中测试一项服务。该服务正在加载到测试中,但忽略了http
请求。
该服务包含:
console.log('test') //this is shown withing the karma console
$http.get("myjson.json").then(function(data) {
this.data = data.data;
}); // this isn't executed
测试:
describe("Testing http request in service.", function() {
beforeEach(module('myAPP'));
var service, gHttp;
beforeEach(inject(function($injector,$rootScope , $httpBackend, myService) {
service = myService;
gHttp = $httpBackend;
}));
it('should work', function() {
gHttp.flush();
//Error: No pending request to flush !
});
});
答案 0 :(得分:0)
您需要先使用$httpBackend
gHttp.expectGET('myjson.json')
期望值