chrisrzhou / react-wordcloud

☁️ Simple React + D3 wordcloud component with powerful features.

Home Page:https://react-wordcloud.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react-testing-library cannot test wordcloud

David-Cohen35 opened this issue · comments

Wordcloud cannot be tested with react-testing-library - it errors when rendering the component with - Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

`import { render, screen } from "@testing-library/react";
import ReactWordcloud from "react-wordcloud";

describe("", () => {
it("should render the WordCloud component", () => {
render(
<ReactWordcloud
data-testid="word-cloud"
words={[{ text: "foo", value: 1 }]}
/>
);
expect(screen.getByTestId("word-cloud")).toBeInTheDocument();
});
});
`
here is a reproduction of the error -
https://github.com/David-Cohen35/wordcloud-testing-issue

fixed by importing as const ReactWordcloud = require("react-wordcloud").default