You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
If either onFulfilled or onRejected returns a value that is not a promise, promise2 must be fulfilled with that value.
If either onFulfilled or onRejected throws an exception, promise2 must be rejected with the thrown exception as the reason.
However, when using Karma to test a module, I noticed that the following inside the method under test failed:
return $http.post(endpoint, data).then(function(response) {
//return some data from the response
}, function(error) {
var throwable;
//grab some data from the response to create a meaningful rejection reason
throw throwable;
});
When invoking the method as follows, with a mocked HTTP backend to force a failure:
service.do(args).then(function(unused) {
expect(false).toBe(true);//In the absence of a fail() method, use a contradiction
}, function(error) {
expect(error.code).toBe(FAILURE_VAL);
});
Instead of the expectation being met in the onRejected function, the exception propagates up the stack and fails the test. This is because apparently during tests, the default policy of $exceptionHandler is rethrow.
I don't understand what business $exceptionHandler has at all being invoked by $q, especially since this behavior violates the Promises/A specification. Exceptions being thrown is a normal and expected part of promise execution.