Here's how my function looks like.
var myFunc = function(){
return functionReturningaPromise()
.then(function(){
//success, doesn't matter what happens here
})
.catch(function(err){
//handle error here and then throw to handle higher
throw new Error('Error in my function');
})
}
I need the function to be this way to handle an error inside this function and then throw an error to handle on higher level. But i don't know how to test it with jasmine. I know how to control the promises for testing and my basic set up looks like this:
it('Should throw an error', inject(function(alert) {
var instance = instanceFactory.createInstance(someData);
var deferred = $q.defer();
spyOn(someFactory, 'someMethod').and.returnValue(deferred.promise);
//instance contains the throwing function above
instance.myFunc(otherData);
deferred.reject({data: '12 - error'});
$rootScope.$digest();
expect(instance.myFunc).toThrow();
}));
Obviously, the error is not found by jasmine. So how to test the error throw in this case