diff options
| author | Misko Hevery | 2012-03-23 13:31:20 -0700 | 
|---|---|---|
| committer | Misko Hevery | 2012-03-23 14:21:43 -0700 | 
| commit | ac75079e2113949d5d64adbcf23d56f3cf295d41 (patch) | |
| tree | 7956bcbd50de73755d599b624677666e20419595 | |
| parent | 5390fb37d2c01937922613fc57df4986af521787 (diff) | |
| download | angular.js-ac75079e2113949d5d64adbcf23d56f3cf295d41.tar.bz2 | |
fix(q): resolve all of nothing to nothing
$q.all([]) no longer throws exception and resolves to empty array []
| -rw-r--r-- | src/service/q.js | 22 | ||||
| -rw-r--r-- | test/service/qSpec.js | 8 | 
2 files changed, 21 insertions, 9 deletions
| diff --git a/src/service/q.js b/src/service/q.js index f0c030b0..074acd1d 100644 --- a/src/service/q.js +++ b/src/service/q.js @@ -364,16 +364,20 @@ function qFactory(nextTick, exceptionHandler) {          counter = promises.length,          results = []; -    forEach(promises, function(promise, index) { -      promise.then(function(value) { -        if (index in results) return; -        results[index] = value; -        if (!(--counter)) deferred.resolve(results); -      }, function(reason) { -        if (index in results) return; -        deferred.reject(reason); +    if (counter) { +      forEach(promises, function(promise, index) { +        ref(promise).then(function(value) { +          if (index in results) return; +          results[index] = value; +          if (!(--counter)) deferred.resolve(results); +        }, function(reason) { +          if (index in results) return; +          deferred.reject(reason); +        });        }); -    }); +    } else { +      deferred.resolve(results); +    }      return deferred.promise;    } diff --git a/test/service/qSpec.js b/test/service/qSpec.js index e592ab87..a230d1de 100644 --- a/test/service/qSpec.js +++ b/test/service/qSpec.js @@ -676,6 +676,14 @@ describe('q', function() {    describe('all', function() { +    it('should resolve all of nothing', function() { +      var result; +      q.all([]).then(function(r) { result = r; }); +      mockNextTick.flush(); +      expect(result).toEqual([]); +    }); + +      it('should take an array of promises and return a promise for an array of results', function() {        var deferred1 = defer(),            deferred2 = defer(); | 
