Skip to content

Commit

Permalink
Ensure that Promise.all() works on array-like objects as well as arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
cscott committed Feb 14, 2014
1 parent 7ea1664 commit ea66963
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions test/promise/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ require('../../'); // import Promise from es6-shim

var assert = require("assert");

var failIfThrows = function(done) {
return function(e) { done(e); };
};

describe("Promise.all", function () {
it("fulfills if passed an empty array", function (done) {
var iterable = [];
Expand All @@ -11,7 +15,18 @@ describe("Promise.all", function () {
assert(Array.isArray(value));
assert.deepEqual(value, []);
done();
});
}, failIfThrows(done));
});

it("fulfills if passed an empty array-like", function (done) {
var f = function() {
Promise.all(arguments).then(function (value) {
assert(Array.isArray(value));
assert.deepEqual(value, []);
done();
}, failIfThrows(done));
};
f();
});

it("fulfills if passed an array of mixed fulfilled promises and values", function (done) {
Expand All @@ -21,7 +36,7 @@ describe("Promise.all", function () {
assert(Array.isArray(value));
assert.deepEqual(value, [0, 1, 2, 3]);
done();
});
}, failIfThrows(done));
});

it("rejects if any passed promise is rejected", function (done) {
Expand Down Expand Up @@ -52,7 +67,7 @@ describe("Promise.all", function () {
Promise.all(iterable).then(function (value) {
assert.deepEqual(value, [1, 2]);
done();
});
}, failIfThrows(done));
});

it("fulfills when passed an sparse array, giving `undefined` for the omitted values", function (done) {
Expand All @@ -61,7 +76,7 @@ describe("Promise.all", function () {
Promise.all(iterable).then(function (value) {
assert.deepEqual(value, [0, undefined, undefined, 1]);
done();
});
}, failIfThrows(done));
});

it("does not modify the input array", function (done) {
Expand All @@ -71,7 +86,7 @@ describe("Promise.all", function () {
Promise.all(iterable).then(function (value) {
assert.notStrictEqual(input, value);
done();
});
}, failIfThrows(done));
});


Expand Down Expand Up @@ -100,9 +115,6 @@ describe("Promise.all", function () {
}
});
};
var failIfThrows = function(done) {
return function(e) { done(e); };
};

it("should be robust against tampering (1)", function(done) {
var g = [ tamper(Promise.resolve(0)) ];
Expand Down

0 comments on commit ea66963

Please sign in to comment.