Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: toEqual throws error when comparing readonly properties #9575

Merged
merged 3 commits into from
Feb 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: toEqual throws error when comparing readonly properties
  • Loading branch information
doniyor2109 committed Feb 15, 2020
commit 9a36e7fb2880d89961e6f359b607e6880acc62ee
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