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
This commit is contained in:
Igor Minar 2012-04-02 10:10:46 -07:00
parent 59fa40ec0e
commit c0b78478a0
2 changed files with 9 additions and 1 deletions

View file

@ -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;
}

View file

@ -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)']);
});
});