Skip to content

Commit

Permalink
fix(expect): Object.freeze breaks toEqual (#4303)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing authored Oct 16, 2023
1 parent a25f601 commit a4501d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/utils/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function clone<T>(
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
}

Expand All @@ -110,7 +110,7 @@ export function clone<T>(
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,
Expand Down
7 changes: 7 additions & 0 deletions test/core/test/jest-expect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit a4501d6

Please sign in to comment.