- Instalaciones:
npm install -D jest babel-jest @babel/preset-env @babel/preset-react
npm install -D @testing-library/react @types/jest jest-environment-jsdom
- if Fetch API:
npm install -D whatwg-fetch
- package.json
"scripts: {
...
"test": "jest --watchAll"
- babel.config.js
module.exports = {
presets: [
[ '@babel/preset-env', { targets: { esmodules: true } } ],
[ '@babel/preset-react', { runtime: 'automatic' } ],
],
};
- Jest config & setup:
jest.config.js
module.exports = {
testEnvironment: 'jest-environment-jsdom',
setupFiles: ['./jest.setup.js']
}
jest.setup.js
import 'whatwg-fetch';