0

I have a factory which has a method which does a $http call . it takes two obj params and 4 callbacks . How do i unit test the method and it's callbacks using Karma -Jasmine ? all the other answers on stack aren't helping me with callbacks .

app.factory('somefactory', ['$http','$rootScope','dependency',
function($http, $rootScope,dependency){

var factory = {
//two obj params and 4 callback parmas           
  method:function(obj1,obj2,succCallbk,failureCallbk,errCallbk,completeCallbk){
        $http({
          method: obj.method,
          url: url,
          data: requestData
        }).success(function(data, status, headers, config){
             if(someCondition){
            _succCallbk(data, status);
            }
             if(someCondition){
            _completeCallbk(data, status);
            }
          })
          .error(function(err){
           if(someCondition){
             _errCallbk()}
            })
           }
          };
 return factory;
})
Jeson Dias
  • 883
  • 2
  • 11
  • 26
  • Possible duplicate of [How to unit test $http in angularjs and Jasmine](http://stackoverflow.com/questions/31108273/how-to-unit-test-http-in-angularjs-and-jasmine) – Slava.K Feb 23 '17 at 06:42
  • The problem with callbacks is that they force you to defer the responsability of the control flow to the asynchronous function you are invoking. Promises solve that problem. **Don't add callbacks to a promise based API**. See [Why are Callbacks from Promise `.then` Methods an Anti-Pattern](http://stackoverflow.com/questions/35660881/why-are-callbacks-from-promise-then-methods-an-anti-pattern). Also see [Why are angular $http success/error methods deprecated? Removed from v1.6?](http://stackoverflow.com/a/35331339/5535245). Use the `.then` and `.catch` methods instead. – georgeawg Feb 23 '17 at 06:54
  • Well this is not my code base . so i can't edit it at least right now. i think this project is using Angular 1.3 . I know that .success and .error were deprecated in successive versions of angular – – Jeson Dias Feb 27 '17 at 05:34

0 Answers0