Adding this question because I didn't easily find the answer online.
I am trying to use react-testing-library to test that a component renders correctly. However I get numerous errors that don't seem to help much.
Here is my test file (report.test.ts, alongside the component in the code):
import { render } from "react-testing-library";
import "jest-dom/extend-expect";
import Report from "./Report";
test("component", () => {
const reportData = {
name: "test-report-name",
url: "test-url"
};
const { getByText } = render(<Report report={reportData} />);
expect(getByText("test-report-name")).toHaveAttribute("href", "test-url");
});
When I try to run the test, I get the error SyntaxError: Unexpected token, expected "</>". There is a red squiggly line in VS Code that on hover says Argument of type 'Report' is not assignable to parameter of type 'ReactElement<any>'.
Even if I change the Report tag to be simply <div />, then I get Cannot find name 'div'.
What is the problem with my test?