I am experiencing an issue with the following code:
function foo(){
bar().catch(function(){
//do stuff
}
}
function bar(){
return promiseReturner().then(
function(result){
if(_.isEmpty(result)){
throw "Result is empty";
}
}
)
}
My goal is to test that the //do stuff
block is executed when result
is empty:
deferred.resolve(null);
foo();
$rootScope.$apply();
Although the throw
block is triggered, it seems that the catch
function does not catch it. Strangely, this behavior only occurs in the testing environment, as outside of tests it works correctly.
Why is the catch block not being triggered in my test code?