react-test-renderer: is possible to test lifecycle functions?
See original GitHub issueDo you want to request a feature or report a bug?
Question
What is the current behavior?
I am trying to use react-test-renderer and I notice that the lifecycles methods (ex: componentDidMount) need to be fired manually - rendered.getInstance().componentDidMount(), what solves my problem but reveals an other: I want to use shallow render, to test only the component under test, but then react-test-renderer/shallow API is minimal for rendering.
What is the expected behavior?
I was expecting that react-test-renderer would support testing my component reaction to the different lifecycles and be capable to use shallow rendering. Is there some way to use react-test-renderer in this scenario? Or is better I move to another library like enzyme?
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Test Renderer - React
This package provides a React renderer that can be used to render React components to pure JavaScript objects, without depending on the DOM...
Read more >Testing React Components with react-test-renderer, and the ...
react -test-renderer is a library for rendering React components to pure JavaScript objects, but it can do a lot more than creating objects....
Read more >Unit Testing Behavior of React Components with Test-Driven ...
When we want to validate that the component's children are rendered, or if we need the full component lifecycle and environment runtime methods,...
Read more >When testing a React component, is there any way to directly ...
I saw that Call a React component method from outside suggested this should be possible - simply render the component in the test...
Read more >A Complete Guide to Testing React Hooks - Toptal
Hooks were introduced in React 16.8 in late 2018. They are functions that hook into a functional component and allow us to use...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Test renderer has no opinions about whether your code is synchronous or asynchronous. Just like ReactDOM doesn’t care about this.
When you call
setStateyour component will re-render. Both with ReactDOM and with test renderer.But how I test componentDidUpdate? Please help me!