diff --git a/CHANGELOG.md b/CHANGELOG.md index 55b489aacf33..0daa54b614b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Fixes +- `[expect]` Handle readonly properties correctly ([#9575](https://github.com/facebook/jest/pull/9575)) - `[jest-config]` Treat `setupFilesAfterEnv` like `setupFiles` when normalizing configs against presets ([#9495](https://github.com/facebook/jest/pull/9495)) - `[jest-config]` Support `.mjs` config files on Windows as well ([#9558](https://github.com/facebook/jest/pull/9558)) - `[jest-config]` Verify `rootDir` and all `roots` are directories ([#9569](https://github.com/facebook/jest/pull/9569)) diff --git a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap index 4c19643b51b9..4da9c13f4d09 100644 --- a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap @@ -2113,6 +2113,20 @@ exports[`.toEqual() {pass: false} expect({"a": 5}).toEqual({"b": 6}) 1`] = ` } `; +exports[`.toEqual() {pass: false} expect({"foo": {"bar": 1}}).toEqual({"foo": {}}) 1`] = ` +expect(received).toEqual(expected) // deep equality + +- Expected - 1 ++ Received + 3 + + Object { +- "foo": Object {}, ++ "foo": Object { ++ "bar": 1, ++ }, + } +`; + exports[`.toEqual() {pass: false} expect({"nodeName": "div", "nodeType": 1}).toEqual({"nodeName": "p", "nodeType": 1}) 1`] = ` expect(received).toEqual(expected) // deep equality diff --git a/packages/expect/src/__tests__/matchers.test.js b/packages/expect/src/__tests__/matchers.test.js index 55d11a9bc8f9..0b9695e00d9d 100644 --- a/packages/expect/src/__tests__/matchers.test.js +++ b/packages/expect/src/__tests__/matchers.test.js @@ -434,6 +434,7 @@ describe('.toEqual()', () => { [/abc/gsy, /abc/g], [{a: 1}, {a: 2}], [{a: 5}, {b: 6}], + [Object.freeze({foo: {bar: 1}}), {foo: {}}], ['banana', 'apple'], ['1\u{00A0}234,57\u{00A0}$', '1 234,57 $'], // issues/6881 [ diff --git a/packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts b/packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts index 9d81675ff0e6..59f5e160b600 100644 --- a/packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts +++ b/packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts @@ -59,6 +59,10 @@ function deepCyclicCopyObject(object: T, cycles: WeakMap): T { descriptor.value = deepCyclicCopyReplaceable(descriptor.value, cycles); } + if (!('set' in descriptor)) { + descriptor.writable = true; + } + descriptor.configurable = true; });