mercredi 24 mai 2017

jasmine - how to chain a .then and a .finally in a callFake spy

I have the following function, that does a servicecall with a promise and a .finally:

myService.getStuff().then(function() {
   this.doStuffWhenServiceOK();
}, function () {
   this.doStuffWhenServiceFails();
}).finally(function() {
   this.doFinally();
});

I am spying on this service with the following spy:

spyOn(myService, 'getStuff').and.callFake(function() {
   return {
     then: function (succesFn, errorFn) {
              return succesFn();
           }
   };
});

the problem is, that the test complains that the .finally is not known. Just adding it after the .then does not seem to be a solution... so like this:

  return {
            then: function(successFn) { 
                    return successFn();
                  },
            finally: function(successFn) {
                    return successFn();
                  }
         }

Who knows how to chain the then and the finally in the callFake spy? :D I work with Angular1

Aucun commentaire:

Enregistrer un commentaire