- Instalaciones:
yarn add --dev jest babel-jest @babel/preset-env @babel/preset-react
yarn add --dev @testing-library/react @types/jest jest-environment-jsdom
- Opcional: Si usamos Fetch API en el proyecto:
yarn add --dev whatwg-fetch
- Actualizar los scripts del package.json
"scripts: {
...
"test": "jest --watchAll"
- Crear la configuración de babel babel.config.js
module.exports = {
presets: [
[ '@babel/preset-env', { targets: { esmodules: true } } ],
[ '@babel/preset-react', { runtime: 'automatic' } ],
],
};
- Opcional, pero eventualmente necesario, crear Jest config y setup:
jest.config.js
module.exports = {
testEnvironment: 'jest-environment-jsdom',
setupFiles: ['./jest.setup.js']
}
jest.setup.js
// En caso de necesitar la implementación del FetchAPI
import 'whatwg-fetch'; // <-- yarn add whatwg-fetch
for all those whom has issues setting the enviroment along jest and react testing library, you should not use the "commonjs" : "module" at the package.json if the files created has the .js file type assigned, once you check that, you should match the dependencies on the original package.json file made by Fernando H. attached at the end of the lesson seccion 5, and run the next commnads on yarn , yarn install --inmmutable , yarn clean cache , yarn bin , yarn test this willl works. cause if you wants to use the common js the solution for all those errors is to switch npm and manage the babel configs} for a better set experience.