Jest: Cannot assign to read only property '...' of object '...'
See original GitHub issueRight 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]’

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:
- Created 3 years ago
- Reactions:9
- Comments:11 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
To be clear, this issue is specifically about improving the error message 😄 because the current one is unhelpful and confusing.
Same here, for me in:
The assertion had failed because the expectation was incorrect. After the expectation was fixed the test passed.