React-Test-Renderer@16 breaks trying to use internal property
See original GitHub issueUsing version 16.0.0, I get a TypeError: Cannot read property 'ReactCurrentOwner' of undefined
Sample test case https://github.com/eddiemonge/snapshots-broken but really its just:
{
"scripts": {
"test": "jest"
},
"devDependencies": {
"jest": "^21.2.1",
"react": "^16.0.0",
"react-test-renderer": "^16.0.0"
}
}
var ReactTestRenderer = require('react-test-renderer');
Error thrown is:
FAIL ./test.spec.js
● Test suite failed to run
TypeError: Cannot read property 'ReactCurrentOwner' of undefined
at node_modules/react-test-renderer/cjs/react-test-renderer.development.js:622:36
at Object.<anonymous> (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:8255:3)
at Object.<anonymous> (node_modules/react-test-renderer/index.js:6:20)
at Object.<anonymous> (test.spec.js:1:114)
at Generator.next (<anonymous>)
at Promise (<anonymous>)
at Generator.next (<anonymous>)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
Offending code is
var ReactInstanceMap_1 = ReactInstanceMap;
var ReactInternals = react.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
var ReactGlobalSharedState = {
ReactCurrentOwner: ReactInternals.ReactCurrentOwner
};
Seems like maybe from this change? https://github.com/facebook/react/pull/9366
Issue Analytics
- State:
- Created 6 years ago
- Comments:18 (7 by maintainers)
Top Results From Across the Web
Test Renderer - React
This package provides a React renderer that can be used to render React components to pure JavaScript objects, without depending on the DOM...
Read more >How to test a react component that is dependent on ...
There's a number of ways to make this work, but only approach I've found that works with 'react-test-renderer/shallow' is to inject a mock...
Read more >react-test-renderer | Yarn - Package Manager
Design simple views for each state in your application, and React will efficiently update and render just the right components when your data...
Read more >How to Test React Components: the Complete Guide
unit testing: testing an isolated part of your app, usually done in combination with shallow rendering. example: a component renders with the ...
Read more >Testing React Components with react-test-renderer, and the ...
Snapshot testing is a feature built into the Jest test runner and since it's the default library for testing React we'll make use...
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
Make sure
react-test-renderer
version is the same withreact
,react-dom
versionI modified the code to:
It ran fine for me:
My guess is something is wrong with your environment, and you don’t actually have
react@16
there. Maybe you have a badpackage-lock.json
or something like this.Make sure you’re using
react@16
and it should work.Happy to reopen if you can provide a reproducing example that does reproduce the bug.