mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-21 01:57:06 +08:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user