ResponsiveContainer cannot be rendered and hence cannot be tested using react testing library
See original GitHub issue- I have searched the issues of this repository and believe that this is not a duplicate.
Reproduction link
Steps to reproduce
- Use ResponsiveContainer to render a chart
- Render the chart component with react testing library
What is expected?
The chart should get rendered
What is actually happening?
<div class="recharts-responsive-container makeStyles-chart-21" style="width: 100%; height: 300px;">
<div style="position: absolute; width: 0px; height: 0px; visibility: hidden; display: none;"/>
</div>
The chart is hidden with 0 height and width. No dom nodes are created for the chart.
Environment | Info |
---|---|
Recharts | v1.8.5 |
React | 16.13.0 |
System | macOS Mojave 10.14.6 |
Browser | React testing library |
The chart is rendered while testing if ResponsiveContainer is replaced with a div.
Issue Analytics
- State:
- Created 3 years ago
- Comments:14
Top Results From Across the Web
Writing unit tests with react testing library for recharts
Two things you can try: mock the responsiveContainer with at least one fixed width/height value like so;. jest.mock("recharts" ...
Read more >[React] Writing tests with Charts | by J.Kim - Medium
ResponsiveContainer cannot be rendered and hence cannot be tested using react testing library ·… I have searched the issues of this repository and...
Read more >API | Testing Library
React Testing Library re-exports everything from DOM Testing Library as well.
Read more >react.development.js:1622 uncaught typeerror: cannot read ...
getting error "Uncaught (in promise) TypeError: Cannot read properties of null (reading ... "git+https://github.com/anmdsystems/test-component-library.git".
Read more >Test Utilities - React
ReactTestUtils makes it easy to test React components in the testing framework of your choice. At Facebook we use Jest for painless JavaScript...
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 FreeTop 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
Top GitHub Comments
You’re a life-saver, @krzysu! This was making me crazy. The only thing I’ll add is that I had to return all the other recharts components as-is with spread syntax on the original module.
Thanks again!
you mock ResponsiveContainer in your test, something like below: