mercredi 7 janvier 2015

mocking services containing http request

I have a service which provides methods returning http request for my controllers like so:



angular.module('sandboxApp').factory('API', function ($http) {
return {
'newRequest': function (path, conf) {
return $http.get('http://ift.tt/1tGnrLm' + path, conf);
},
'baseURL': 'http://ift.tt/1tGnrLm'
};
})


How can i mock it when im unit testing my controller ? Simple use of httpBackend as shown in angular documentation wouldn't work because http requests arent made directly on a controller but through service.


Aucun commentaire:

Enregistrer un commentaire