I am trying to add the jest-dom library to every test file. I installed that package and made the "jestSetup.js" file and add the package.json as below.
"jest":{
setupFilesAfterEnv:["<rootDir>/jestSetup.js"]
}
and jestSetup.js is
import @testing-library/jest-dom;
console.log("jest-dom")
the test file is
import { render } from "@testing-library/svelte";
...
console.log("test")
expect(getByText("success notification")).toHaveClass("success");
...
But it says toHaveClass is not defined
error
And the result of console.log is "jest-dom, jest"
I tested it with jest.config.js again but the result is the same.
I am not sure why it happens.
Your node-module should have quotes.
Change this:
import @testing-library/jest-dom;
To this:
import '@testing-library/jest-dom';