- Install Testing library packages and types
yarn add --dev @testing-library/jest-dom @types/testing-library__jest-dom @testing-library/react @testing-library/user-event
- Create
setupTests.ts
file at /src
with this content:
import '@testing-library/jest-dom/extend-expect';
- Add jest dom sixteen
yarn add --dev jest-environment-jsdom-sixteen
- Add this section in your
package.json
"jest": {
"collectCoverageFrom": [
"src/**/*.{ts,tsx}"
],
"setupFilesAfterEnv": [
"<rootDir>/src/setupTests.ts",
],
"modulePaths": [
"<rootDir>/src"
],
"testEnvironment": "jest-environment-jsdom-sixteen"
}
- Add helpfull eslint plugins
yarn add --dev eslint-plugin-jest-dom eslint-plugin-react-hooks eslint-plugin-testing-library
- Add this configs to your
eslint.json
...
"extends": [
...
"plugin:jest-dom/recommended",
"plugin:react-hooks/recommended",
"plugin:testing-library/recommended",
"plugin:testing-library/react",
...
],
...
"plugins": [
...
"react-hooks",
"jest-dom",
"testing-library",
...
],
...
"overrides": [
{
...
"env": {
"node": true,
"commonjs": true,
"browser": true,
"jest": true
}
}
]
Thank you. This helped!