enzymejs / enzyme

JavaScript Testing utilities for React
https://enzymejs.github.io/enzyme/
MIT License
19.95k stars 2.01k forks source link

Enzyme mount(): TypeError: Cannot read property 'rendered' of null #1217

Closed Keksike closed 6 years ago

Keksike commented 7 years ago

Similar problem as https://github.com/airbnb/enzyme/issues/1195

This is possibly a problem with https://github.com/Root-App/react-native-mock-render

TypeError: Cannot read property 'rendered' of null

      at Object.getNode (node_modules/enzyme-adapter-react-16/build/ReactSixteenAdapter.js:233:69)
      at new ReactWrapper (node_modules/enzyme/build/ReactWrapper.js:100:33)
      at mount (node_modules/enzyme/build/mount.js:19:10)
      at createTestApp (test/testHelper.js:20:27)
      at Object._callee$ (test/container-component/container.test.js:13:35)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:63:29)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:337:12)
      at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:96:13)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:63:29)
      at invoke (node_modules/regenerator-runtime/runtime.js:139:12)

My versions:

react@16.0.0-alpha.6
react-test-renderer@16.0.0
enzyme@3.0.0
enzyme-adapter-react-16@1.0.0

react-native@0.44.0
react-native-mock-render@0.0.9
jest@21.2.1

My test-code which produces the problem: https://gist.github.com/Keksike/8afd4787f80c08e4e6d36c24a7886510

eddiemonge commented 7 years ago

Happens without react-native as well

eddiemonge commented 7 years ago

I create a super basic test repo that shows this failing https://github.com/eddiemonge/enzyme-3-simple-test

michaelgmcd commented 6 years ago

Ran into this issue and did some debugging myself. Enzyme relies on the instance._reactInternalFiber property which did not exist until a later version of React. This did not work for me on react-native version 0.49.3 (the latest version at the moment) which uses react 16.0.0-beta.5. Updating to react@16.0.0 fixed this issue.

ljharb commented 6 years ago

Sounds like we need to up the peer dep on the react 16 adapter to a later version; @michaelgmcd, do you know which exact react 16 version added that property?

michaelgmcd commented 6 years ago

I've only briefly looked into this, but it looks like this commit made the change and it was released in react 16.0.0-rc.1 according to this release candidate issue

ljharb commented 6 years ago

ok - we should lift the peer dep to that.

patrickford commented 6 years ago

Is anyone else getting this error when trying to launch Enzyme setupTests.js: TypeError: Cannot read property 'ReactCurrentOwner' of undefined

drewjenkins commented 6 years ago

@patrickford I got that error when I was using this adapter but was actually still pulling in React 15.X instead of 16.X

patrickford commented 6 years ago

Thanks. We eventually figured that out. It was a project started a while back and was still on 15.x.


From: Andrew Jenkins notifications@github.com Sent: Friday, February 23, 2018 8:19 AM To: airbnb/enzyme Cc: Patrick Ford; Mention Subject: Re: [airbnb/enzyme] Enzyme mount(): TypeError: Cannot read property 'rendered' of null (#1217)

@patrickfordhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fpatrickford&data=02%7C01%7C%7C854279fbba79405f7f5d08d57ad93da4%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636549995809031267&sdata=OYzX6so%2BWrZeON4HblyR6%2BT6Q8yPCV%2B2hFGNjvHHZx4%3D&reserved=0 I got that error when I was using this adapter but was actually still pulling in React 15.X instead of 16.X

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fairbnb%2Fenzyme%2Fissues%2F1217%23issuecomment-368057499&data=02%7C01%7C%7C854279fbba79405f7f5d08d57ad93da4%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636549995809031267&sdata=Rp6HJK47fuigpzXQHzs%2Bf79izlNEJ4z8Msj%2B0AACc5M%3D&reserved=0, or mute the threadhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAsUdm30NLb8K5fxI49MK8TnJSK6Bp7Vks5tXuURgaJpZM4PrrwO&data=02%7C01%7C%7C854279fbba79405f7f5d08d57ad93da4%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636549995809031267&sdata=PG3EohnSNW17nmxiTh9Ioehy1adf%2BZrcOx%2BGqdaqyZo%3D&reserved=0.

developer239 commented 6 years ago

Make sure that you have enzyme-adapter-react-16 🙂

ljharb commented 6 years ago

This seems closeable; please file a new issue if there's still problems.

sanatg7582 commented 3 years ago

This seems closeable; please file a new issue if there's still problems.

I am using react version 17 and enzyme-adapter-react-16 getting an error : TypeError: Cannot read property 'child' of undefined

ljharb commented 3 years ago

@sanatg7582 enzyme does not support react 17 yet; downgrade to v16 for now, and see #2429.