question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Cannot assign to read only property '...' of object '...'

See original GitHub issue

šŸ› Bug Report

Manually transferring https://github.com/facebook/react/issues/18758 to here. During debugging, it was determined to be a Jest issue.

@gaearon rightly agreed with me that the issue wonā€™t get fixed by sitting in the React repo. But they used their facebook admin powers to lock the issue, instead of using GitHubā€™s ā€œTransfer Issueā€ feature to get it here with all its detail in an instant. Ah, well.

People (including React repo maintainers, apparently) are seeing variations on TypeError: Cannot assign to read only property 'Symbol(...)' of object '[object ...]' when they do expect(...).toBe(...) and expect(...).toEqual(...).

The initial response is that itā€™s not a very helpful error message.

Hereā€™s one clue that might explain it:

It happens when calling replaceMatchedToAsymmetricMatcher() inside printDiffOrStringify()

https://github.com/facebook/jest/blob/master/packages/jest-matcher-utils/src/index.ts#L359

@SimenB any ideas?

_Originally posted by @pahan35 in https://github.com/facebook/react/issues/18758#issuecomment-636249433_

And a suggestion about what should be done about it:

We see a current message because replaceMatchedToAsymmetricMatcher fails on preparing the diff.

IMHO itā€™s not about improving the error message, itā€™s about fixing replaceMatchedToAsymmetricMatcher to print the diff for DOM elements without failures.

_Originally posted by @pahan35 in https://github.com/facebook/react/issues/18758#issuecomment-647179531_

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ahnpnlcommented, Aug 15, 2020

Found problem at

https://github.com/facebook/jest/blob/c9c8dba4dd8de34269bdb971173659399bcbfd55/packages/jest-matcher-utils/src/deepCyclicCopyReplaceable.ts#L58-L74

We need to set symbol key property descriptor.

But I got error on typescript that symbol type cannot be object key. An index signature parameter type must be either 'string' or 'number'.

Will continue work tomorrow.

If anyone interested in, welcom to take it.

https://github.com/microsoft/TypeScript/issues/1863 Probably related to the error

1reaction
WeiAnAncommented, Aug 15, 2020

Sorry guys. Iā€™m trying to figure out the problem and solve it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot assign to read only property of Object in TypeScript
The TypeScript error "Cannot assign to read only property of object" occurs when we try to change a property of a frozen object...
Read more >
Uncaught TypeError: Cannot assign to read only property
When you use Object.defineProperties , by default writable is set to false , so _year and edition are actually read only properties.
Read more >
[Cannot assign to read only property '<field_name>' of object ...
This type of error(Cannot assign to read-only property) generally occurs on update of public property @api decorator variable value.
Read more >
TypeError: "x" is read-only - JavaScript - MDN Web Docs
The JavaScript strict mode-only exception "is read-only" occurs when a global variable or object property that was assigned to is a read-only property....
Read more >
TypeError: Cannot assign to read only property of object ...
The issue arises when you are passing in an immutable object as your default values. In my case I was directly passing in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found