From 1996100990856c2591eaa6a9a9fbf63b6c9ec5e8 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Sat, 14 Oct 2023 00:49:02 +0800 Subject: [PATCH 1/3] fix(jest-expect): Object.freeze breaks toEqual --- packages/utils/src/error.ts | 7 +++++-- test/core/test/jest-expect.test.ts | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/utils/src/error.ts b/packages/utils/src/error.ts index dc2aeb0d5aac..a3be38ef8e57 100644 --- a/packages/utils/src/error.ts +++ b/packages/utils/src/error.ts @@ -163,8 +163,11 @@ export function replaceAsymmetricMatcher(actual: any, expected: any, actualRepla actualReplaced, expectedReplaced, ) - actual[key] = replaced.replacedActual - expected[key] = replaced.replacedExpected + if (actualValue !== replaced.replacedActual) + actual[key] = replaced.replacedActual + + if (expectedValue !== replaced.replacedExpected) + expected[key] = replaced.replacedExpected } }) return { 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', () => { From 2b3d469f8ab02ce3b7e0d00678158734bbdfbe41 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Sun, 15 Oct 2023 09:41:13 +0800 Subject: [PATCH 2/3] refactor: should passing options to next clone --- packages/utils/src/error.ts | 7 ++----- packages/utils/src/helpers.ts | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/utils/src/error.ts b/packages/utils/src/error.ts index a3be38ef8e57..dc2aeb0d5aac 100644 --- a/packages/utils/src/error.ts +++ b/packages/utils/src/error.ts @@ -163,11 +163,8 @@ export function replaceAsymmetricMatcher(actual: any, expected: any, actualRepla actualReplaced, expectedReplaced, ) - if (actualValue !== replaced.replacedActual) - actual[key] = replaced.replacedActual - - if (expectedValue !== replaced.replacedExpected) - expected[key] = replaced.replacedExpected + actual[key] = replaced.replacedActual + expected[key] = replaced.replacedExpected } }) return { diff --git a/packages/utils/src/helpers.ts b/packages/utils/src/helpers.ts index e0fca92c693a..7b936c7c0d07 100644 --- a/packages/utils/src/helpers.ts +++ b/packages/utils/src/helpers.ts @@ -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, From fc445c550e7caf97c2d868c48602cb7eaa12853b Mon Sep 17 00:00:00 2001 From: Dunqing Date: Mon, 16 Oct 2023 13:16:56 +0800 Subject: [PATCH 3/3] fix: missing --- packages/utils/src/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/utils/src/helpers.ts b/packages/utils/src/helpers.ts index 7b936c7c0d07..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 }