Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit c0b7847

Browse files
committed
fix($q): $q.reject should forward callbacks if missing
$q.reject('some reason').then() should not blow up, but correctly forward the callbacks instead. Closes #845
1 parent 59fa40e commit c0b7847

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/ng/q.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ function qFactory(nextTick, exceptionHandler) {
274274
then: function(callback, errback) {
275275
var result = defer();
276276
nextTick(function() {
277-
result.resolve(errback(reason));
277+
result.resolve((errback || defaultErrback)(reason));
278278
});
279279
return result.promise;
280280
}

test/ng/qSpec.js

+8
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,14 @@ describe('q', function() {
480480
syncResolve(deferred, rejectedPromise);
481481
expect(log).toEqual(['error(Error: not gonna happen)']);
482482
});
483+
484+
485+
it('should return a promise that forwards callbacks if the callbacks are missing', function() {
486+
var rejectedPromise = q.reject('rejected');
487+
promise.then(success(), error());
488+
syncResolve(deferred, rejectedPromise.then());
489+
expect(log).toEqual(['error(rejected)']);
490+
});
483491
});
484492

485493

0 commit comments

Comments
 (0)