Started a new create-react-app which comes with all the necessary react testing lib stuff pre installed:
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
i have tried to write basic test for one of my components:
import "@testing-library/jest-dom";
import React from "react";
import { render } from "@testing-library/react";
import SomeComponent from "./SomeComponent";
describe("helllo", () => {
it("renders SomeComponent correctley", () => {
const { queryAllByPlaceholderText } = render(<SomeComponent />);
console.log(test);
expect(test).toBeTruthy();
});
});
But i am getting this error message in the console:
Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
6 | describe("helllo", () => {
7 | it("renders SomeComponent correctley", () => {
> 8 | const { queryAllByPlaceholderText } = render(<SomeComponent />);
| ^
My react version is:
"react": "^17.0.2",
I have researched this issue and keep on bumping into bable stuff but i though the react-testing-lib should be working out of box...?