How to karma test .config where $httpProvider is used in a service layer?

浪尽此生 提交于 2019-12-04 16:10:51

I suggest you to test if requests have correct header:

// Assume $httpBackend and $http have been properly injected above
it('should have correct Content-Type header on GET request', function() {
    $httpBackend.expectGET('/api-call', function(headers) {
       return headers['Content-Type'] === 'application/json';
    }).respond(200, {});
    $http.get('/api-call');
    $httpBackend.flush();
});
// ... and do the same for POST and PUT requests
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!