vendredi 29 janvier 2016

Promise catch not being caught in test

I have some code that looks like:

function foo(){
  bar().catch(function(){
    //do stuff
  }
}

function bar(){
  return promiseReturner().then(
    function(result){
      if(_.isEmpty(result)){
        throw "Result is empty";
      }
    }
  )
}

I'm trying to test that the //do stuff block is called when result is empty:

deferred.resolve(null);
foo();
$rootScope.$apply();

Now this does actually trigger the throw block, but for some reason that throw block is not being caught by the catch function. Whats more interesting is that when this same code runs outside of the test environment, it behaves as expected.

Why am I unable to trigger the catch block in my test code?

Aucun commentaire:

Enregistrer un commentaire