4

setup vitest + testing library

 1 year ago
source link: https://gist.github.com/thiagobraddock/030d548c09869ef5087b7dcc28538f50
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

setup vitest + testing library · GitHub

Instantly share code, notes, and snippets.

setup vitest + testing library
  1. Instalação:
npm i vitest -D
npm i jsdom -D
npm i @testing-library/react @testing-library/jest-dom @testing-library/user-event -D
  1. Acrescentar os scripts teste e coverage ao package.json:
"scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview",
  + "test": "vitest",
  + "coverage": "vitest run --coverage",
  },
  1. Acrescentar config ao vite.config (abaixo).

  2. Criar o setupTest.js na raiz do projeto (abaixo).

  3. Criar o arquivo de teste e executa-lo com o comando npm run test

  4. Ao executar o comando npm run coverage pela primeira vez, será perguntado se deseja instalar o pacote '@vitest/coverage-c8', aperte Y para confirmar.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK