## Installs and configuration for Jest + React Testing Library ## For React + Vite projects 1. Necessary installs: ``` yarn add --dev jest babel-jest @babel/preset-env @babel/preset-react yarn add --dev @testing-library/react @types/jest jest-environment-jsdom ``` 2. Optional: If we use Fetch API in the project: ``` yarn add --dev whatwg-fetch ``` 3. Update __package.json__ scripts ``` "scripts: { ... "test": "jest --watchAll" ``` 4. Create babel configuration file __babel.config.js__. Warning!: if you get a module type error, rename file to extension __.cjs__ ``` module.exports = { presets: [ [ '@babel/preset-env', { targets: { esmodules: true } } ], [ '@babel/preset-react', { runtime: 'automatic' } ], ], }; ``` 5. Optional, but eventually necessary, create Jest config and setup: __jest.config.js__ ``` module.exports = { testEnvironment: 'jest-environment-jsdom', setupFiles: ['./jest.setup.js'] } ``` __jest.setup.js__ ``` // In case you need to implement the FetchAPI import 'whatwg-fetch'; // <-- yarn add whatwg-fetch ```