1
我試圖在業障中測試服務。服務正在加載到測試中,但http
請求被忽略。Karma忽略服務中的角度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 !
});
});