Skip to content

Commit a4501d6

Browse files
authored
fix(expect): Object.freeze breaks toEqual (#4303)
1 parent a25f601 commit a4501d6

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/utils/src/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function clone<T>(
9797
if (Array.isArray(val)) {
9898
out = Array((k = val.length))
9999
seen.set(val, out)
100-
while (k--) out[k] = clone(val[k], seen)
100+
while (k--) out[k] = clone(val[k], seen, options)
101101
return out as any
102102
}
103103

@@ -110,7 +110,7 @@ export function clone<T>(
110110
const descriptor = Object.getOwnPropertyDescriptor(val, k)
111111
if (!descriptor)
112112
continue
113-
const cloned = clone((val as any)[k], seen)
113+
const cloned = clone((val as any)[k], seen, options)
114114
if ('get' in descriptor) {
115115
Object.defineProperty(out, k, {
116116
...descriptor,

test/core/test/jest-expect.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,13 @@ describe('jest-expect', () => {
303303
expect(() => {
304304
expect(complex).toHaveProperty('a-b', false)
305305
}).toThrowErrorMatchingInlineSnapshot('"expected { \'0\': \'zero\', foo: 1, …(4) } to have property "a-b" with value false"')
306+
307+
expect(() => {
308+
const x = { a: { b: { c: 1 } } }
309+
const y = { a: { b: { c: 2 } } }
310+
Object.freeze(x.a)
311+
expect(x).toEqual(y)
312+
}).toThrowErrorMatchingInlineSnapshot(`"expected { a: { b: { c: 1 } } } to deeply equal { a: { b: { c: 2 } } }"`)
306313
})
307314

308315
it('assertions', () => {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy