From c0b78478a0e64942a69aba7c1bfa4eb01c0e9a5e Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Mon, 2 Apr 2012 10:10:46 -0700 Subject: [PATCH] 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 --- src/ng/q.js | 2 +- test/ng/qSpec.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ng/q.js b/src/ng/q.js index 074acd1de447..b8e1166ebc61 100644 --- a/src/ng/q.js +++ b/src/ng/q.js @@ -274,7 +274,7 @@ function qFactory(nextTick, exceptionHandler) { then: function(callback, errback) { var result = defer(); nextTick(function() { - result.resolve(errback(reason)); + result.resolve((errback || defaultErrback)(reason)); }); return result.promise; } diff --git a/test/ng/qSpec.js b/test/ng/qSpec.js index a230d1de5ee7..941b4f2ea63d 100644 --- a/test/ng/qSpec.js +++ b/test/ng/qSpec.js @@ -480,6 +480,14 @@ describe('q', function() { syncResolve(deferred, rejectedPromise); expect(log).toEqual(['error(Error: not gonna happen)']); }); + + + it('should return a promise that forwards callbacks if the callbacks are missing', function() { + var rejectedPromise = q.reject('rejected'); + promise.then(success(), error()); + syncResolve(deferred, rejectedPromise.then()); + expect(log).toEqual(['error(rejected)']); + }); });