setup vitest + testing library
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.
setup vitest + testing library · GitHub
Instantly share code, notes, and snippets.
- Instalação:
npm i vitest -D
npm i jsdom -D
npm i @testing-library/react @testing-library/jest-dom @testing-library/user-event -D
- Acrescentar os scripts
teste
ecoverage
ao package.json:
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
+ "test": "vitest",
+ "coverage": "vitest run --coverage",
},
-
Acrescentar config ao
vite.config
(abaixo). -
Criar o
setupTest.js
na raiz do projeto (abaixo). -
Criar o arquivo de teste e executa-lo com o comando
npm run test
-
Ao executar o comando
npm run coverage
pela primeira vez, será perguntado se deseja instalar o pacote'@vitest/coverage-c8'
, aperteY
para confirmar.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK