Commit d8d19e41 authored by Teddy Zeenny's avatar Teddy Zeenny

Throw exception in all called without an array

parent 71f121c1
import { Promise } from "rsvp/promise"; import { Promise } from "rsvp/promise";
function all(promises) { function all(promises) {
if(toString.call(promises) !== "[object Array]") {
throw new TypeError('You must pass an array to all.');
}
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
var results = [], remaining = promises.length, var results = [], remaining = promises.length,
promise; promise;
......
...@@ -483,6 +483,20 @@ describe("RSVP extensions", function() { ...@@ -483,6 +483,20 @@ describe("RSVP extensions", function() {
assert(RSVP.all); assert(RSVP.all);
}); });
it('throws when not passed an array', function() {
assert.throws(function () {
var all = RSVP.all();
}, TypeError);
assert.throws(function () {
var all = RSVP.all('');
}, TypeError);
assert.throws(function () {
var all = RSVP.all({});
}, TypeError);
});
specify('fulfilled only after all of the other promises are fulfilled', function(done) { specify('fulfilled only after all of the other promises are fulfilled', function(done) {
var firstResolved, secondResolved, firstResolver, secondResolver; var firstResolved, secondResolved, firstResolver, secondResolver;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment