Skip to content

Commit

Permalink
fix: toEqual throws error when comparing readonly properties (#9575)
Browse files Browse the repository at this point in the history
  • Loading branch information
doniyor2109 authored Feb 16, 2020
1 parent 83aad69 commit d4a10f7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
14 changes: 14 additions & 0 deletions packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2113,6 +2113,20 @@ exports[`.toEqual() {pass: false} expect({"a": 5}).toEqual({"b": 6}) 1`] = `
<d> }</>
`;

exports[`.toEqual() {pass: false} expect({"foo": {"bar": 1}}).toEqual({"foo": {}}) 1`] = `
<d>expect(</><r>received</><d>).</>toEqual<d>(</><g>expected</><d>) // deep equality</>

<g>- Expected - 1</>
<r>+ Received + 3</>

<d> Object {</>
<g>- "foo": Object {},</>
<r>+ "foo": Object {</>
<r>+ "bar": 1,</>
<r>+ },</>
<d> }</>
`;

exports[`.toEqual() {pass: false} expect({"nodeName": "div", "nodeType": 1}).toEqual({"nodeName": "p", "nodeType": 1}) 1`] = `
<d>expect(</><r>received</><d>).</>toEqual<d>(</><g>expected</><d>) // deep equality</>

Expand Down
1 change: 1 addition & 0 deletions packages/expect/src/__tests__/matchers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
[
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ function deepCyclicCopyObject<T>(object: T, cycles: WeakMap<any, any>): T {
descriptor.value = deepCyclicCopyReplaceable(descriptor.value, cycles);
}

if (!('set' in descriptor)) {
descriptor.writable = true;
}

descriptor.configurable = true;
});

Expand Down

0 comments on commit d4a10f7

Please sign in to comment.