From a4501d6bdca04e701c618055339f417afc5446b6 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Mon, 16 Oct 2023 02:19:23 -0500 Subject: [PATCH] fix(expect): `Object.freeze` breaks `toEqual` (#4303) --- packages/utils/src/helpers.ts | 4 ++-- test/core/test/jest-expect.test.ts | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/utils/src/helpers.ts b/packages/utils/src/helpers.ts index e0fca92c693a..5a3b454a8d8b 100644 --- a/packages/utils/src/helpers.ts +++ b/packages/utils/src/helpers.ts @@ -97,7 +97,7 @@ export function clone( if (Array.isArray(val)) { out = Array((k = val.length)) seen.set(val, out) - while (k--) out[k] = clone(val[k], seen) + while (k--) out[k] = clone(val[k], seen, options) return out as any } @@ -110,7 +110,7 @@ export function clone( const descriptor = Object.getOwnPropertyDescriptor(val, k) if (!descriptor) continue - const cloned = clone((val as any)[k], seen) + const cloned = clone((val as any)[k], seen, options) if ('get' in descriptor) { Object.defineProperty(out, k, { ...descriptor, diff --git a/test/core/test/jest-expect.test.ts b/test/core/test/jest-expect.test.ts index f51ddb967a52..9387910cc0b9 100644 --- a/test/core/test/jest-expect.test.ts +++ b/test/core/test/jest-expect.test.ts @@ -303,6 +303,13 @@ describe('jest-expect', () => { expect(() => { expect(complex).toHaveProperty('a-b', false) }).toThrowErrorMatchingInlineSnapshot('"expected { \'0\': \'zero\', foo: 1, …(4) } to have property "a-b" with value false"') + + expect(() => { + const x = { a: { b: { c: 1 } } } + const y = { a: { b: { c: 2 } } } + Object.freeze(x.a) + expect(x).toEqual(y) + }).toThrowErrorMatchingInlineSnapshot(`"expected { a: { b: { c: 1 } } } to deeply equal { a: { b: { c: 2 } } }"`) }) it('assertions', () => {