Skip to content

Instantly share code, notes, and snippets.

@Klerith
Last active July 7, 2025 22:11
Show Gist options
  • Save Klerith/3a3d8df27c19755c829ee5c0cef55a55 to your computer and use it in GitHub Desktop.
Save Klerith/3a3d8df27c19755c829ee5c0cef55a55 to your computer and use it in GitHub Desktop.
Configuración de Vitest + React Testing Library

Instalar dependencias Testing

  1. Vitest
npm install --save-dev vitest jsdom
  1. React Testing Library
npm install --save-dev @testing-library/react @testing-library/dom
  • Todo en un sólo comando
npm install --save-dev @testing-library/react @testing-library/dom vitest jsdom
  1. Crear estos scripts en el package.json
"scripts": {
  "test": "vitest",
  "test:ui": "vitest --ui",
  "coverage": "vitest run --coverage"
}
  1. Configurar vite.config.ts
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react-swc';

// https://vite.dev/config/
export default defineConfig({
  plugins: [react()],
  test: {
    environment: 'jsdom',
    globals: true,
  },
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment