react: React-Test-Renderer@16 breaks trying to use internal property
Using 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
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 18 (1 by maintainers)
Make sure
react-test-rendererversion is the same withreact,react-domversionI 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@16there. Maybe you have a badpackage-lock.jsonor something like this.Make sure you’re using
react@16and it should work.Happy to reopen if you can provide a reproducing example that does reproduce the bug.
It is documented in a form of peer dependency. If you install
react-test-rendererwith a wrong version ofreact, your package manager will warn you that it’s not supported.As of React 16, they don’t have to be exact.
react-test-renderer@16.xshould work with any version ofreactthat also has 16 as a major.You’re welcome to submit a PR to the documentation. It’s here: http://github.com/reactjs/reactjs.org.
I had an older version of React/test installed globally somehow. removing those, forcing a cache clean, and then reinstalling locally fixed the problem. so i think something was trying to use the global version