Background
In the react channel on Spectrum, someone asked how to test that a component displayed data provided by location.state from r...
For further actions, you may consider blocking this person and/or reporting abuse
That sort of worked for me, but I still had code in my component that was throwing an error "cannot access property .state of null value", in this case the null value was
location.I did come up with a solution, which is to first grab the history of the component I'm rendering to test and then
rerenderthat component with alocationprop equal tohistory.location. Looking like:That way, my code in the
<Component/>that callsthis.props.location.statedoesn't fail.Sidenote:
renderWithRouteris a utility function I built that uses similar logic to what you have above and returnshistoryalong with...render(<Component />That worked perfectly for me! Thanks for the writeup!
Thanks for the post!
A heads up: eslint will throw
Don't do it - stackoverflow.com/a/66787971/863110.
How to solve this beside make eslint ignoring the line? I have no idea 😕