Skip to content

Commit 2734762

Browse files
slowcheetahzloirock
authored andcommitted
Update Promise.allKeyed tests
1 parent 483fb55 commit 2734762

File tree

2 files changed

+123
-74
lines changed

2 files changed

+123
-74
lines changed

tests/unit-global/esnext.promise.all-keyed.js

Lines changed: 55 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ QUnit.test('Promise.allKeyed', assert => {
66
assert.true(Promise.allKeyed({}) instanceof Promise, 'returns a promise');
77
});
88

9-
QUnit.test('Promise.allKeyed, rejected on incorrect input', assert => {
10-
return Promise.allKeyed('string').then(() => {
11-
assert.avoid();
12-
}, error => {
13-
assert.true(error instanceof TypeError, 'error is TypeError');
14-
assert.required('rejected as expected');
15-
});
16-
});
17-
189
QUnit.test('Promise.allKeyed, resolved', assert => {
1910
return Promise.allKeyed({
2011
a: Promise.resolve(1),
@@ -56,6 +47,15 @@ QUnit.test('Promise.allKeyed, resolved with hidden attributes', assert => {
5647
});
5748
});
5849

50+
QUnit.test('Promise.allKeyed, rejected on incorrect input', assert => {
51+
return Promise.allKeyed('string').then(() => {
52+
assert.avoid();
53+
}, error => {
54+
assert.true(error instanceof TypeError, 'error is TypeError');
55+
assert.required('rejected as expected');
56+
});
57+
});
58+
5959
QUnit.test('Promise.allKeyed, resolved with timeouts', assert => {
6060
return Promise.allKeyed({
6161
a: Promise.resolve(1),
@@ -70,6 +70,52 @@ QUnit.test('Promise.allKeyed, resolved with timeouts', assert => {
7070
});
7171
});
7272

73+
QUnit.test('Promise.allKeyed, subclassing', assert => {
74+
const { allKeyed, resolve } = Promise;
75+
function SubPromise(executor) {
76+
executor(() => { /* empty */ }, () => { /* empty */ });
77+
}
78+
SubPromise.resolve = resolve.bind(Promise);
79+
assert.true(allKeyed.call(SubPromise, { a: Promise.resolve(1) }) instanceof SubPromise, 'subclassing, `this` pattern');
80+
81+
function FakePromise1() { /* empty */ }
82+
function FakePromise2(executor) {
83+
executor(null, () => { /* empty */ });
84+
}
85+
function FakePromise3(executor) {
86+
executor(() => { /* empty */ }, null);
87+
}
88+
FakePromise1.resolve = FakePromise2.resolve = FakePromise3.resolve = resolve.bind(Promise);
89+
assert.throws(() => {
90+
allKeyed.call(FakePromise1, { a: Promise.resolve(1) });
91+
}, 'NewPromiseCapability validations, #1');
92+
assert.throws(() => {
93+
allKeyed.call(FakePromise2, { a: Promise.resolve(1) });
94+
}, 'NewPromiseCapability validations, #2');
95+
assert.throws(() => {
96+
allKeyed.call(FakePromise3, { a: Promise.resolve(1) });
97+
}, 'NewPromiseCapability validations, #3');
98+
});
99+
100+
QUnit.test('Promise.allKeyed, without constructor context', assert => {
101+
const { allKeyed } = Promise;
102+
assert.throws(() => allKeyed({ a: Promise.resolve(1) }), TypeError, 'Throws if called without a constructor context');
103+
assert.throws(() => allKeyed.call(null, { a: Promise.resolve(1) }), TypeError, 'Throws if called with null as this');
104+
});
105+
106+
QUnit.test('Promise.allKeyed, result object has null prototype', assert => {
107+
return Promise.allKeyed({
108+
a: Promise.resolve(1),
109+
b: Promise.resolve(2),
110+
}).then(result => {
111+
assert.strictEqual(
112+
Object.getPrototypeOf(result),
113+
null,
114+
'Result object has null prototype',
115+
);
116+
});
117+
});
118+
73119
QUnit.test('Promise.allKeyed, symbol keys', assert => {
74120
const symA = Symbol('A');
75121
const symB = Symbol('B');
@@ -94,34 +140,3 @@ QUnit.test('Promise.allKeyed, keys order', assert => {
94140
assert.deepEqual(actualKeys, ['a', 'b', 'c'], 'correct order in the case when promises resolves in different order');
95141
});
96142
});
97-
98-
QUnit.test('Promise.allKeyed, without constructor context', assert => {
99-
const { allKeyed } = Promise;
100-
assert.throws(() => allKeyed({ a: 1 }), TypeError, 'Throws if called without a constructor context');
101-
assert.throws(() => allKeyed.call(null, { a: 1 }), TypeError, 'Throws if called with null as this');
102-
});
103-
104-
QUnit.test('Promise.allKeyed, fake promises', assert => {
105-
const { allKeyed } = Promise;
106-
const FakePromise1 = function (executor) {
107-
executor(() => { /* empty */ }, () => { /* empty */ });
108-
};
109-
const FakePromise2 = FakePromise1[Symbol.species] = function (executor) {
110-
executor(() => { /* empty */ }, () => { /* empty */ });
111-
};
112-
FakePromise1.resolve = FakePromise2.resolve = Promise.resolve.bind(Promise);
113-
assert.true(allKeyed.call(FakePromise1, { a: Promise.resolve(1) }) instanceof FakePromise1, 'subclassing, `this` pattern');
114-
});
115-
116-
QUnit.test('Promise.allKeyed, result object has null prototype', assert => {
117-
return Promise.allKeyed({
118-
a: Promise.resolve(1),
119-
b: Promise.resolve(2),
120-
}).then(result => {
121-
assert.strictEqual(
122-
Object.getPrototypeOf(result),
123-
null,
124-
'Result object has null prototype',
125-
);
126-
});
127-
});

tests/unit-pure/esnext.promise.all-keyed.js

Lines changed: 68 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import $allKeyed from '@core-js/pure/full/promise/all-keyed';
12
import Promise from '@core-js/pure/full/promise';
23
import Symbol from '@core-js/pure/full/symbol';
34
import Object from '@core-js/pure/full/object';
@@ -8,15 +9,6 @@ QUnit.test('Promise.allKeyed', assert => {
89
assert.true(Promise.allKeyed({}) instanceof Promise, 'returns a promise');
910
});
1011

11-
QUnit.test('Promise.allKeyed, rejected on incorrect input', assert => {
12-
return Promise.allKeyed('string').then(() => {
13-
assert.avoid();
14-
}, error => {
15-
assert.true(error instanceof TypeError, 'error is TypeError');
16-
assert.required('rejected as expected');
17-
});
18-
});
19-
2012
QUnit.test('Promise.allKeyed, resolved', assert => {
2113
return Promise.allKeyed({
2214
a: Promise.resolve(1),
@@ -58,6 +50,15 @@ QUnit.test('Promise.allKeyed, resolved with hidden attributes', assert => {
5850
});
5951
});
6052

53+
QUnit.test('Promise.allKeyed, rejected on incorrect input', assert => {
54+
return Promise.allKeyed('string').then(() => {
55+
assert.avoid();
56+
}, error => {
57+
assert.true(error instanceof TypeError, 'error is TypeError');
58+
assert.required('rejected as expected');
59+
});
60+
});
61+
6162
QUnit.test('Promise.allKeyed, resolved with timeouts', assert => {
6263
return Promise.allKeyed({
6364
a: Promise.resolve(1),
@@ -72,6 +73,64 @@ QUnit.test('Promise.allKeyed, resolved with timeouts', assert => {
7273
});
7374
});
7475

76+
QUnit.test('Promise.allKeyed, subclassing', assert => {
77+
const { allKeyed, resolve } = Promise;
78+
function SubPromise(executor) {
79+
executor(() => { /* empty */ }, () => { /* empty */ });
80+
}
81+
SubPromise.resolve = resolve.bind(Promise);
82+
assert.true(allKeyed.call(SubPromise, { a: Promise.resolve(1) }) instanceof SubPromise, 'subclassing, `this` pattern');
83+
84+
function FakePromise1() { /* empty */ }
85+
function FakePromise2(executor) {
86+
executor(null, () => { /* empty */ });
87+
}
88+
function FakePromise3(executor) {
89+
executor(() => { /* empty */ }, null);
90+
}
91+
FakePromise1.resolve = FakePromise2.resolve = FakePromise3.resolve = resolve.bind(Promise);
92+
assert.throws(() => {
93+
allKeyed.call(FakePromise1, { a: Promise.resolve(1) });
94+
}, 'NewPromiseCapability validations, #1');
95+
assert.throws(() => {
96+
allKeyed.call(FakePromise2, { a: Promise.resolve(1) });
97+
}, 'NewPromiseCapability validations, #2');
98+
assert.throws(() => {
99+
allKeyed.call(FakePromise3, { a: Promise.resolve(1) });
100+
}, 'NewPromiseCapability validations, #3');
101+
});
102+
103+
QUnit.test('Promise.allKeyed, without constructor context', assert => {
104+
const { allKeyed } = Promise;
105+
assert.throws(() => allKeyed({ a: Promise.resolve(1) }), TypeError, 'Throws if called without a constructor context');
106+
assert.throws(() => allKeyed.call(null, { a: Promise.resolve(1) }), TypeError, 'Throws if called with null as this');
107+
});
108+
109+
QUnit.test('Promise.allKeyed, method from direct entry, without constructor context', assert => {
110+
return $allKeyed({ a: Promise.resolve(1) }).then(it => {
111+
assert.deepEqual(it, { a: 1 }, 'resolved with a correct value');
112+
});
113+
});
114+
115+
QUnit.test('Promise.allKeyed, method from direct entry, with null context', assert => {
116+
return $allKeyed.call(null, { a: Promise.resolve(1) }).then(it => {
117+
assert.deepEqual(it, { a: 1 }, 'resolved with a correct value');
118+
});
119+
});
120+
121+
QUnit.test('Promise.allKeyed, result object has null prototype', assert => {
122+
return Promise.allKeyed({
123+
a: Promise.resolve(1),
124+
b: Promise.resolve(2),
125+
}).then(result => {
126+
assert.strictEqual(
127+
Object.getPrototypeOf(result),
128+
null,
129+
'Result object has null prototype',
130+
);
131+
});
132+
});
133+
75134
QUnit.test('Promise.allKeyed, symbol keys', assert => {
76135
const symA = Symbol('A');
77136
const symB = Symbol('B');
@@ -96,28 +155,3 @@ QUnit.test('Promise.allKeyed, keys order', assert => {
96155
assert.deepEqual(actualKeys, ['a', 'b', 'c'], 'correct order in the case when promises resolves in different order');
97156
});
98157
});
99-
100-
QUnit.test('Promise.allKeyed, fake promises', assert => {
101-
const { allKeyed } = Promise;
102-
const FakePromise1 = function (executor) {
103-
executor(() => { /* empty */ }, () => { /* empty */ });
104-
};
105-
const FakePromise2 = FakePromise1[Symbol.species] = function (executor) {
106-
executor(() => { /* empty */ }, () => { /* empty */ });
107-
};
108-
FakePromise1.resolve = FakePromise2.resolve = Promise.resolve.bind(Promise);
109-
assert.true(allKeyed.call(FakePromise1, { a: Promise.resolve(1) }) instanceof FakePromise1, 'subclassing, `this` pattern');
110-
});
111-
112-
QUnit.test('Promise.allKeyed, result object has null prototype', assert => {
113-
return Promise.allKeyed({
114-
a: Promise.resolve(1),
115-
b: Promise.resolve(2),
116-
}).then(result => {
117-
assert.strictEqual(
118-
Object.getPrototypeOf(result),
119-
null,
120-
'Result object has null prototype',
121-
);
122-
});
123-
});

0 commit comments

Comments
 (0)