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.

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

See original GitHub issue

Right now in the React repo this test…

fit('blah', () => {
  expect(document.createElement('div')).toBe(document.createElement('div'));
});

…fails with the following meaningless error message:

TypeError: Cannot assign to read only property ‘Symbol(impl)’ of object ‘[object DOMImplementation]’

Screen Shot 2020-04-27 at 2 04 19 PM

Apparently @trueadm mentions that this broke sometime recently because of a change we made. (I don’t have details.) Its a pretty confusing behavior though.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
bvaughncommented, Jun 21, 2020

To be clear, this issue is specifically about improving the error message 😄 because the current one is unhelpful and confusing.

2reactions
jcestibarizcommented, May 14, 2020

Same here, for me in:

expect(fn.mock.calls).toEqual([[element]]);

The assertion had failed because the expectation was incorrect. After the expectation was fixed the test passed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest: How to fix - TypeError: Cannot assign to read only ...
I faced the same issue for window.location.reload : TypeError: Cannot assign to read only property 'reload' of object '[object Location]'.
Read more >
[Bug]: Cannot assign to read only property 'test' of object ...
The only difference here is that Jest tries to mock a property on an object rather than on a module. But both are...
Read more >
How to mock read-only property in jest | by kozo yamagata
I'm going to explain this problem with a function that validates an image file size. The function checks if that the size is...
Read more >
Cannot assign to read only property of Object in JavaScript
The error "Cannot assign to read only property of object" occurs when we try to change a property of an object that has...
Read more >
Cannot assign to read only property 'X' of object ... - Reddit
This is most likely the issue, wired properties are immutable I believe. Best way to handle this is by using the spread operator...
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