forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathes.promise.all.js
More file actions
66 lines (64 loc) · 2.33 KB
/
Copy pathes.promise.all.js
File metadata and controls
66 lines (64 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { createIterable } from '../helpers/helpers';
import getIteratorMethod from 'core-js-pure/es/get-iterator-method';
import Promise from 'core-js-pure/es/promise';
import Symbol from 'core-js-pure/es/symbol';
import bind from 'core-js-pure/es/function/bind';
QUnit.test('Promise.all', assert => {
const { all, resolve } = Promise;
assert.isFunction(all);
assert.arity(all, 1);
const iterable = createIterable([1, 2, 3]);
Promise.all(iterable).catch(() => { /* empty */ });
assert.true(iterable.received, 'works with iterables: iterator received');
assert.true(iterable.called, 'works with iterables: next called');
const array = [];
let done = false;
array['@@iterator'] = undefined;
array[Symbol.iterator] = function () {
done = true;
return getIteratorMethod([]).call(this);
};
Promise.all(array);
assert.true(done);
assert.throws(() => {
all.call(null, []).catch(() => { /* empty */ });
}, TypeError, 'throws without context');
done = false;
try {
Promise.resolve = function () {
throw new Error();
};
Promise.all(createIterable([1, 2, 3], {
return() {
done = true;
},
})).catch(() => { /* empty */ });
} catch (error) { /* empty */ }
Promise.resolve = resolve;
assert.true(done, 'iteration closing');
let FakePromise1 = function (executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
};
let FakePromise2 = FakePromise1[Symbol.species] = function (executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
};
FakePromise1.resolve = FakePromise2.resolve = bind(resolve, Promise);
assert.true(all.call(FakePromise1, [1, 2, 3]) instanceof FakePromise1, 'subclassing, `this` pattern');
FakePromise1 = function () { /* empty */ };
FakePromise2 = function (executor) {
executor(null, () => { /* empty */ });
};
const FakePromise3 = function (executor) {
executor(() => { /* empty */ }, null);
};
FakePromise1.resolve = FakePromise2.resolve = FakePromise3.resolve = bind(resolve, Promise);
assert.throws(() => {
all.call(FakePromise1, [1, 2, 3]);
}, 'NewPromiseCapability validations, #1');
assert.throws(() => {
all.call(FakePromise2, [1, 2, 3]);
}, 'NewPromiseCapability validations, #2');
assert.throws(() => {
all.call(FakePromise3, [1, 2, 3]);
}, 'NewPromiseCapability validations, #3');
});