- Isntallations:
yarn add --dev jest babel-jest @babel/preset-env @babel/preset-react
yarn add --dev @testing-library/react @types/jest jest-environment-jsdom
- Optional: If we use Fetch API in the project:
yarn add --dev whatwg-fetch
- Update the scripts of package.json
"scripts: {
...
"test": "jest --watchAll"
- Create babel configuration babel.config.js
module.exports = {
presets: [
[ '@babel/preset-env', { targets: { esmodules: true } } ],
[ '@babel/preset-react', { runtime: 'automatic' } ],
],
};
- 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