2014-03-19 67 views
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 ! 
    }); 
}); 

回答

0

您需要與gHttp.expectGET('myjson.json')

先設置 $httpBackend預期