Skip to content

Instantly share code, notes, and snippets.

@CarmeloRicarte
Last active November 29, 2022 12:52
Show Gist options
  • Save CarmeloRicarte/ca27487919e53af9530bbc71af18b8cb to your computer and use it in GitHub Desktop.
Save CarmeloRicarte/ca27487919e53af9530bbc71af18b8cb to your computer and use it in GitHub Desktop.
Vitest-Testing Library React - Typescript
  1. Instalaciones
    yarn add -D vitest jsdom @vitest/ui @testing-library/react @testing-library/jest-dom @vitest/coverage-c8
  2. Configuraciones
    2.1 Crear el archivo setupTests.ts en el root con lo siguiente:
    import "@testing-library/jest-dom";
    import matchers from "@testing-library/jest-dom/matchers";
    import { expect } from "vitest";
    expect.extend(matchers);
    2.2 En el tsconfig.json, insertar lo siguiente dentro de compilerOptions: "types": ["vitest/globals"]
    2.3 En vite.config.ts
    • al principio del archivo:
      /// <reference types="vitest" />
      /// <reference types="vitest/globals"/>
    • añadir lo siguiente al defineConfig:
      test: { environment: 'jsdom', globals: true, setupFiles: "./setupTests.ts", }
      2.4 En package.json, añadir lo siguiente dentro de scripts:
      "test": "vitest",
      "test:ui": "vitest --ui",
      "coverage": "vitest run --coverage"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment