I have and angular service that I want to test. In one of his methods I am using $http of angular service. I am simply want to mock that function (to be more specific mock $http.post function) that would return whatever I want and inject this mock to my service test.
I am tried to find solution and I found $httpBackend but I am not sure that this could help me.
MyService looks like that:
angular.module('app').service('MyService' , function (dependencies) {
let service = this;
service.methodToTest = function () {
$http.post('url').then(function () {
// Do something
});
}
}
- I am want to test methodToTest and inject the mock of $http.post()
P.S please remember that $http.post() returns promise so I think that I need to consider in that.
$http.post
, that seems to be the main problem – Matthias