Skip to content

Repository files navigation

React + TypeScript + Vite

To set up test with Vitest in this project, you require:

VitestDocumentation

These are the commands you'll need to install (I usually use npm):

  1. Install vitest
npm i vitest --save-dev
  1. 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.

  1. Inside your vite-env.d.ts, add the following reference/ parameter:
/// <reference types='vitest'>
  1. 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
  1. 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
  1. 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.

Redux && Redux Toolkit

Instala

  1. Redux Toolkit
  2. React Redux
npm i @reduxjs/toolkit react-redux

React + TS + Vite continuationds

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

  • Configure the top-level parserOptions property like this:
export default tseslint.config({
  languageOptions: {
    // other options...
    parserOptions: {
      project: ['./tsconfig.node.json', './tsconfig.app.json'],
      tsconfigRootDir: import.meta.dirname,
    },
  },
})
  • Replace tseslint.configs.recommended to tseslint.configs.recommendedTypeChecked or tseslint.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,
  },
})

About

Advanced Practice of React and Reacto Hooks with TypeScript

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages