Open joaopedromatias opened 1 year ago
Having the same issue here. I am rendering the line chart as a story in storybook and everything is working great there, but when I try to render the same story with jest, all I get is an empty div like above.
Bump. We have our graphs working for our data visualizations but are unable to regression test using react-testing-library.
I think the reason is here https://github.com/plouc/nivo/blob/master/packages/core/src/components/ResponsiveWrapper.js
The responsive measure not work with Jest environment so width & height always are 0 then nothing are rendered
So I found a solution that is mocking ResponsiveWrapper
component:
jest.mock("@nivo/core", () => ({
...jest.requireActual("@nivo/core"),
ResponsiveWrapper: ({ children }: any) =>
children({ width: 400, height: 400 }),
}));
Then it worked
Great @beohoang98! thank you
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!
Description Unable to render LineChart inside React Testing Library
Reproduce
The DOM rendered does not contain the chart:
Expected behavior It should be rendered by the React Testing Library on the jsdom environment
Desktop (please complete the following information):