Karma在服务中忽略角度HTTP请求

时间:2014-03-19 16:09:54

标签: angularjs karma-runner

我正试图在业力中测试一项服务。该服务正在加载到测试中,但忽略了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 !
    });
});

1 个答案:

答案 0 :(得分:0)

您需要先使用$httpBackend

设置gHttp.expectGET('myjson.json')期望值