Do you want to request a feature or report a bug?
Bug
What is the current behavior?
TypeError: Cannot read property 'current' of undefined
6 | it('renders correctly', () => {
7 | const renderer = new ShallowRenderer()
> 8 | const render = renderer.render(
| ^
9 | <StatusChip
10 | status={'Acknowledged'}
11 | text={'IN PROGRESS'}
at ReactShallowRenderer.render (node_modules/react-test-renderer/cjs/react-test-renderer-shallow.development.js:703:53)
at Object.render (src/components/StatusChip/index.snapshot.test.jsx:8:29)
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
Run ShallowRenderers render method
What is the expected behavior?
render should return shallow render of the given component
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
"react": "16.6.3",
"react-test-renderer": "16.8.0",
"enzyme": "3.7.0",
"enzyme-adapter-react-16": "1.7.0",
"jest": "24.0.0"
Workaround is to add:
"resolutions": {
"react-test-renderer": "16.7.0"
}
(for yarn)
The same problem
https://github.com/facebook/react/blob/master/packages/react-test-renderer/src/ReactShallowRenderer.js#L44 ReactCurrentDispatcher
is undefined
馃槰
for npm you can just install react-test-renderer in your package.json with specific version. We just fixed our problems with this solution.
seems like it works with the latest react version 16.8.0. My previously used version 16.6.3 was failing, probably because the transitive react-test-renderer version was newer and it required something that was not present in the old react version.
I think this is due to us splitting the current owner/dispatcher refs (#14548)
Maybe we could do a bugfix release that patches backwards compat?
To be clear: you can fix this problem if you use the same versions of react
and react-test-renderer
/ react-dom
.
@gaearon in our case react-test-renderer was installed by enzyme-adapter-react-16": "1.7.0 with fixed version. So on local machine with package.json.lock it was fine, but when you push your code in to cloud. It will install all from scratch and i don`t know why but it install last version of react-test-renderer .
To be clear, an older version of the react
package will not work with a newer renderer聽package version鈥撀燽ecause it's trying to access a ReactCurrentDispatcher
which does not exist as a separate ref.
An older renderer _will_ work with a newer version of the react
package.
Possible fix #14770
We'll publish a bugfix release with this fix shortly
Should be fixed by the latest 16.8.1 release
Most helpful comment
To be clear: you can fix this problem if you use the same versions of
react
andreact-test-renderer
/react-dom
.