Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react-test-renderer/shallow render throws TypeError: Cannot read property 'current' of undefined #14763

Closed
vjrasane opened this issue Feb 6, 2019 · 10 comments
Assignees

Comments

@vjrasane
Copy link

vjrasane commented Feb 6, 2019

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)

@alyaptsev
Copy link

The same problem
https://github.com/facebook/react/blob/master/packages/react-test-renderer/src/ReactShallowRenderer.js#L44 ReactCurrentDispatcher is undefined 😨

@DonikaV
Copy link

DonikaV commented Feb 6, 2019

for npm you can just install react-test-renderer in your package.json with specific version. We just fixed our problems with this solution.

@vjrasane
Copy link
Author

vjrasane commented Feb 6, 2019

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.

@bvaughn
Copy link
Contributor

bvaughn commented Feb 6, 2019

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?

@gaearon
Copy link
Collaborator

gaearon commented Feb 6, 2019

To be clear: you can fix this problem if you use the same versions of react and react-test-renderer / react-dom.

@bvaughn bvaughn self-assigned this Feb 6, 2019
@DonikaV
Copy link

DonikaV commented Feb 6, 2019

@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 .

@bvaughn
Copy link
Contributor

bvaughn commented Feb 6, 2019

To be clear, an older version of the react package will not work with a newer renderer package version– because 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.

@bvaughn
Copy link
Contributor

bvaughn commented Feb 6, 2019

Possible fix #14770

@bvaughn
Copy link
Contributor

bvaughn commented Feb 6, 2019

We'll publish a bugfix release with this fix shortly

@bvaughn
Copy link
Contributor

bvaughn commented Feb 6, 2019

Should be fixed by the latest 16.8.1 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
@bvaughn @gaearon @vjrasane @DonikaV @alyaptsev and others