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
TestUtils.renderIntoDocument returns null
when valid functional component passed.
#15370
Comments
Functional components don't have any TestUtils.renderIntoDocument(<FCCounter/>) to return? Also, broadly, can you explain what you're trying to do? You could use |
After calling I am trying to test components that are implemented as functional components. The main objective is to change component’s state and check if changed state match the state expected by the test. In case of testing I have a precondition, that components should be tested as is and should not be altered to contain the code specifically for testing purposes. So, changing component itself to use |
@DeividasBakanas Function components do not have instances. You could trigger the button, which would update state via dispatching an event. In my opinion this is also a better approach than trying to imperatively update the instance returned from |
Like @trueadm mentioned, we do not recommend testing implementation details of the component itself, and use props/events to trigger updates, and do assertions on the component output. I could recommend libraries like react-testing-library https://github.com/kentcdodds/react-testing-library to make this a bit easier. Kent also writes extensively on the topic, would recommend. Closing this issue as it's more a usage question rather than a bug/feature request. |
Do you want to request a feature or report a bug?
I want to report a bug.
What is the current behavior?
Currently when valid functional component is passed to TestUtils.renderIntoDocument it returns a null and raise no error.
Demo
This behavior was reproduced in a sandbox: https://codesandbox.io/s/1zpvll4j24
Check the console, to see TestUtils.renderIntoDocument output of prepared sample components.
Workarounds
Workaround that satisfies both SFC and FC is wrapping component into container:
What is the expected behavior?
Which versions of React are affected by this issue?
React version: 16.8.6
The text was updated successfully, but these errors were encountered: