Skip to content

Commit 876028e

Browse files
committed
Update Promise.allKeyed tests
1 parent eaec9be commit 876028e

File tree

2 files changed

+68
-74
lines changed

2 files changed

+68
-74
lines changed

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

Lines changed: 37 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,34 @@ QUnit.test('Promise.allKeyed, resolved with timeouts', assert => {
7070
});
7171
});
7272

73+
QUnit.test('Promise.allKeyed, subclassing', assert => {
74+
const { allKeyed, resolve } = Promise;
75+
const FakePromise1 = function (executor) {
76+
executor(() => { /* empty */ }, () => { /* empty */ });
77+
};
78+
FakePromise1.resolve = resolve.bind(Promise);
79+
assert.true(allKeyed.call(FakePromise1, { a: Promise.resolve(1) }) instanceof FakePromise1, 'subclassing, `this` pattern');
80+
});
81+
82+
QUnit.test('Promise.allKeyed, without constructor context', assert => {
83+
const { allKeyed } = Promise;
84+
assert.throws(() => allKeyed({ a: 1 }), TypeError, 'Throws if called without a constructor context');
85+
assert.throws(() => allKeyed.call(null, { a: 1 }), TypeError, 'Throws if called with null as this');
86+
});
87+
88+
QUnit.test('Promise.allKeyed, result object has null prototype', assert => {
89+
return Promise.allKeyed({
90+
a: Promise.resolve(1),
91+
b: Promise.resolve(2),
92+
}).then(result => {
93+
assert.strictEqual(
94+
Object.getPrototypeOf(result),
95+
null,
96+
'Result object has null prototype',
97+
);
98+
});
99+
});
100+
73101
QUnit.test('Promise.allKeyed, symbol keys', assert => {
74102
const symA = Symbol('A');
75103
const symB = Symbol('B');
@@ -94,34 +122,3 @@ QUnit.test('Promise.allKeyed, keys order', assert => {
94122
assert.deepEqual(actualKeys, ['a', 'b', 'c'], 'correct order in the case when promises resolves in different order');
95123
});
96124
});
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: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ QUnit.test('Promise.allKeyed', assert => {
88
assert.true(Promise.allKeyed({}) instanceof Promise, 'returns a promise');
99
});
1010

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-
2011
QUnit.test('Promise.allKeyed, resolved', assert => {
2112
return Promise.allKeyed({
2213
a: Promise.resolve(1),
@@ -58,6 +49,15 @@ QUnit.test('Promise.allKeyed, resolved with hidden attributes', assert => {
5849
});
5950
});
6051

52+
QUnit.test('Promise.allKeyed, rejected on incorrect input', assert => {
53+
return Promise.allKeyed('string').then(() => {
54+
assert.avoid();
55+
}, error => {
56+
assert.true(error instanceof TypeError, 'error is TypeError');
57+
assert.required('rejected as expected');
58+
});
59+
});
60+
6161
QUnit.test('Promise.allKeyed, resolved with timeouts', assert => {
6262
return Promise.allKeyed({
6363
a: Promise.resolve(1),
@@ -72,6 +72,28 @@ QUnit.test('Promise.allKeyed, resolved with timeouts', assert => {
7272
});
7373
});
7474

75+
QUnit.test('Promise.allKeyed, subclassing', assert => {
76+
const { allKeyed, resolve } = Promise;
77+
const FakePromise1 = function (executor) {
78+
executor(() => { /* empty */ }, () => { /* empty */ });
79+
};
80+
FakePromise1.resolve = resolve.bind(Promise);
81+
assert.true(allKeyed.call(FakePromise1, { a: Promise.resolve(1) }) instanceof FakePromise1, 'subclassing, `this` pattern');
82+
});
83+
84+
QUnit.test('Promise.allKeyed, result object has null prototype', assert => {
85+
return Promise.allKeyed({
86+
a: Promise.resolve(1),
87+
b: Promise.resolve(2),
88+
}).then(result => {
89+
assert.strictEqual(
90+
Object.getPrototypeOf(result),
91+
null,
92+
'Result object has null prototype',
93+
);
94+
});
95+
});
96+
7597
QUnit.test('Promise.allKeyed, symbol keys', assert => {
7698
const symA = Symbol('A');
7799
const symB = Symbol('B');
@@ -96,28 +118,3 @@ QUnit.test('Promise.allKeyed, keys order', assert => {
96118
assert.deepEqual(actualKeys, ['a', 'b', 'c'], 'correct order in the case when promises resolves in different order');
97119
});
98120
});
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)