These are the commands you'll need to install (I usually use npm):
- Install vitest
npm i vitest --save-dev
- Set in your package.json, site your "scripts" tag:
"scripts": {
"test": "vitest"
}
Please: Do not delete the other tags/ commands that are already configured inside your "scripts" tag.
- Inside your vite-env.d.ts, add the following reference/ parameter:
/// <reference types='vitest'>
- Install jsdom to render elements in the DOM in a node environment, as the elements of the DOM will not trully be rendered
npm i jsdm --save-dev
- Library of user interaction, with the testing library of react. It also work with jest
npm i @testing-library/react @testing-library/jest-dom --save-dev
- User event library from the testing library.
npm i --save-dev @testing-library/user-event
Para que estas pruebas funcionen, es importante que cuando generes el archivo de condifiguracion setup.ts, lo metas en la carpeta:
src/test/setup.ts
Nombrar el carpeta Test en lugar de test hizo que mis pruebas no funcionaran, esto te ahorrará unos minutos.
Instala
- Redux Toolkit
- React Redux
npm i @reduxjs/toolkit react-redux
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
Currently, two official plugins are available:
- @vitejs/plugin-react uses Babel for Fast Refresh
- @vitejs/plugin-react-swc uses SWC for Fast Refresh
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
- Configure the top-level
parserOptionsproperty like this:
export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})- Replace
tseslint.configs.recommendedtotseslint.configs.recommendedTypeCheckedortseslint.configs.strictTypeChecked - Optionally add
...tseslint.configs.stylisticTypeChecked - Install eslint-plugin-react and update the config:
// eslint.config.js
import react from 'eslint-plugin-react'
export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
})