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
Stateless component rendering twice. Jest. Enzyme #6673
Comments
Here is the same example running with the latest react-router version ( And the result is even worst, because the tests do not run at all:
|
That's quite a nasty bug. The problem is that React doesn't have a way to figure out whether or not it should re-render functional components on updates. So it always re-renders them. (That's why React 16.6 introduced React.memo) In short:
I have to revise that. Making redirect a class component isn't enough. :/ |
This was previously addressed in #5003 and fixed by #5162. I'm logging off for the evening right now, but that's roughly what's going on here. I'd argue |
* Redirect: Failing test for rendering in functional component * Properly check if location matches in <Redirect/> Fixes #6673 * Redirect: Handle all eventualities of to strings. * Redirect: Add update depth test with 'to' as location * Redirect: Simplify and rename tests. * Redirect: work around locationsAreEquals quirk.
Version
react-router@4.3.1
Test Case
I wanted to test a simple stateless component that is returning
<Redirect>
when a condition is met.See the code example:
https://codesandbox.io/s/18or04lkp7
pure-component.test.js
test the output is the expected.stateless-component.test.js
the component is rendered twice and a Redirect warning appears: "You tried to redirect to the same route you're currently on:"Steps to reproduce
Expected Behavior
Actual Behavior
Redirect
warningThe text was updated successfully, but these errors were encountered: