Skip to content

Commit 6dc1d18

Browse files
fix(dev): fix relay of custom equality testers (#6140)
1 parent 8ec448d commit 6dc1d18

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/expect/src/jest-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ export function iterableEquality(
538538
) {
539539
const aEntries = Object.entries(a)
540540
const bEntries = Object.entries(b)
541-
if (!equals(aEntries, bEntries)) {
541+
if (!equals(aEntries, bEntries, filteredCustomTesters)) {
542542
return false
543543
}
544544
}

test/core/test/expect.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,28 @@ describe('expect.addEqualityTesters', () => {
155155
})
156156
})
157157

158+
describe('recursive custom equality tester for numeric values', () => {
159+
const areNumbersEqual: Tester = (a, b) => typeof b === 'number' ? a === b : undefined
160+
161+
expect.addEqualityTesters([areNumbersEqual])
162+
163+
test('within objects', () => {
164+
expect({ foo: -0, bar: 0, baz: 0 }).toStrictEqual({ foo: 0, bar: -0, baz: 0 })
165+
})
166+
167+
test('within arrays', () => {
168+
expect([-0, 0, 0]).toStrictEqual([0, -0, 0])
169+
})
170+
171+
test('within typed arrays', () => {
172+
expect(Float64Array.of(-0, 0, 0)).toStrictEqual(Float64Array.of(0, -0, 0))
173+
})
174+
175+
test('within deeply nested structures', () => {
176+
expect({ foo: { bar: [1, [2, 0, [3, -0, 4]]] }, baz: 0 }).toStrictEqual({ foo: { bar: [1, [2, -0, [3, 0, 4]]] }, baz: -0 })
177+
})
178+
})
179+
158180
describe('recursive custom equality tester', () => {
159181
let personId = 0
160182

0 commit comments

Comments
 (0)