Skip to content

Commit dfbeca3

Browse files
ptomatoMs2ger
authored andcommitted
Temporal: Fix mergeFields test for non-string keys
Using assert.deepEqual was faulty here, since deepEqual doesn't take symbol keys into account. This test wasn't actually testing that the symbol keys were absent, and in fact passes if they are present. (Rather than fixing deepEqual, since we hope to deprecate it as per #3476, add a custom assert function in the test.)
1 parent d59d28d commit dfbeca3

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

test/built-ins/Temporal/Calendar/prototype/mergeFields/non-string-properties.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,43 @@ info: |
1313
5. Set additionalFields to ? ToObject(additionalFields).
1414
6. Return ? DefaultMergeFields(fields, additionalFields).
1515
features: [Temporal]
16-
includes: [deepEqual.js]
1716
---*/
1817

18+
function assertEntriesEqual(actual, expectedEntries, message) {
19+
const names = Object.getOwnPropertyNames(actual);
20+
const symbols = Object.getOwnPropertySymbols(actual);
21+
const actualKeys = names.concat(symbols);
22+
assert.sameValue(
23+
actualKeys.length,
24+
expectedEntries.length,
25+
`${message}: expected object to have ${expectedEntries.length} properties, not ${actualKeys.length}:`
26+
);
27+
for (var index = 0; index < actualKeys.length; index++) {
28+
const actualKey = actualKeys[index];
29+
const expectedKey = expectedEntries[index][0];
30+
const expectedValue = expectedEntries[index][1];
31+
assert.sameValue(actualKey, expectedKey, `${message}: key ${index}:`);
32+
assert.sameValue(actual[actualKey], expectedValue, `${message}: value ${index}:`);
33+
}
34+
}
35+
1936
const cal = new Temporal.Calendar("iso8601");
2037

21-
assert.deepEqual(
38+
assertEntriesEqual(
2239
cal.mergeFields({ 1: 2 }, { 3: 4 }),
23-
{ "1": 2, "3": 4 },
40+
[["1", 2], ["3", 4]],
2441
"number keys are actually string keys and are merged as such"
2542
);
26-
assert.deepEqual(
43+
assertEntriesEqual(
2744
cal.mergeFields({ 1n: 2 }, { 2n: 4 }),
28-
{ "1": 2, "2": 4 },
45+
[["1", 2], ["2", 4]],
2946
"bigint keys are actually string keys and are merged as such"
3047
);
3148

3249
const foo = Symbol("foo");
3350
const bar = Symbol("bar");
34-
assert.deepEqual(cal.mergeFields({ [foo]: 1 }, { [bar]: 2 }), {}, "symbol keys are not merged");
51+
assertEntriesEqual(
52+
cal.mergeFields({ [foo]: 1 }, { [bar]: 2 }),
53+
[],
54+
"symbol keys are not merged"
55+
);

0 commit comments

Comments
 (0)