Skip to content
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

Unable to test Responsive bar in react testing library #2085

Closed
yogeshhub opened this issue Jul 26, 2022 · 3 comments
Closed

Unable to test Responsive bar in react testing library #2085

yogeshhub opened this issue Jul 26, 2022 · 3 comments

Comments

@yogeshhub
Copy link

Hi,
I have been using Nivo charts. And it is really awesome with customization.

I am unable to test the Responsive bar component with react testing library. The bar is not rendering in the dom though I couldn't proceed with the test cases.

I double checked the parent height and other data values.

Note: I have tried with the react-test-renderer. but the same result.

These are my configurations,

"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^12.1.5",
"@testing-library/user-event": "^14.2.1",
"@nivo/bar": "^0.72.0",
"@nivo/core": "^0.72.0",

@yogeshhub
Copy link
Author

After debugging the Nivo core library, the responsive wrapper caused the issue by consuming the ResizeObserver browser API. So, we cannot use the ResizeObserver in jest-dom since it is not supported yet.

I have found the workaround for the scenario to mock ResizeObserver and supply the contentRect values from the test.

https://gist.github.com/ErikGMatos/20192d0ee2815a14e8516c16002c6422

@joaopedromatias
Copy link
Contributor

@yogeshhub even mocking the ResizeObserver I'm still not able to render the Line Chart inside of my unit tests.

@plouc
Copy link
Owner

plouc commented Feb 26, 2023

Yes, while fixed dimensions can be tested, the responsive versions cannot as it's not possible to determine the size of the chart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants