-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
wrapper.instance() returns null under React 16 #1250
Comments
SFCs and host nodes don't have instances in React 16. This isn't in the migration guide (because it's React 16-related, not enzyme 3 related) - #1243 will address this by documenting the difference. |
Edit: Nevermind - I figured out my issue. :P If someone else runs into this, you want to replace |
Ah. I see where I went wrong. One of my |
My solution was different, but I'll share to hopefully help someone else. I'm silly, and was using
for a dumb component. All I had to do was NOT use Hopefully my mistake can help guide someone |
Any my mistake was calling it on a functional component :) |
How do we use enzyme to test a functional component? Is there a different way? |
@blu3printchris you don't need the instance to test any component, really - you wrap it, you pass it props, and you assert on what it renders. |
@Ijharb when I'm testing a functional component using react 17 adapter it says access to state is only available in class based components. Is there a way to test functional component states and is there any way to manually trigger renders? |
@saadjhk a) useState is not component state, it’s something else with a bad name - and no, there’s not, and b) there isn’t an official react 17 adapter yet; and c) this is off topic for the issue. Please file a new one if you have further questions. |
To reproduce:
Then create test.js:
And finally:
We expect this to print something exciting, instead it just prints 'null'.
The text was updated successfully, but these errors were encountered: