Questions tagged [vitest]

Vitest is a blazing-fast unit test framework powered by Vite.

501 questions
4
votes
1 answer

How to mock file system with memfs in NodeJS

I want to test the following function with the memfs package import fs from 'fs-extra' import path from 'path' async function ensureParent(filepath: string) { const absolutePath = path.resolve(filepath) const parentDir =…
DavNej
  • 176
  • 3
  • 10
4
votes
0 answers

How to set up mocks for a test in a separate file with Vitest/Jest and Testing Library?

I have the following files in a React app with Vitest (which has the same API as Jest): // hooks/useEntities/useEntities.ts return useEntities() { // this hooks send api requests so I will mock it in the test file. } //…
Matan Gubkin
  • 3,019
  • 6
  • 25
  • 44
4
votes
0 answers

How can I reset the jsdom instance when using vitest in order to test a History-based router?

I'd like to do some integration testing of my svelte + page.js-based router using vitest, but I'm running into an issue where the jsdom instance only updates correctly once per test file. In the following setup, either test will pass when run with…
jrh
  • 4,101
  • 2
  • 22
  • 27
4
votes
1 answer

Vitest: Wrapper doesn't show "teleported" HTML

imagine we have two components, Modal.vue which is lets say a component that is used to display modal content (uses slots to take in JSX), and Component.vue which is the one with content we wish to test with vitest/jest: //Modal.vue