Vitest is a blazing-fast unit test framework powered by Vite.
Questions tagged [vitest]
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
…

ReMo
- 83
- 5
4
votes
0 answers
Vue 2 Composition API + Jest method testing
So previously I have a successfully working test with Vue 2.7 + Jest in Options API like this:
{
data: () => ({}),
methods: {
async someFunction() {
const result = await this.hiWorld()
return result
},
async hiWorld() {
…

Wally Jose
- 141
- 6
4
votes
1 answer
TypeError: default is not a function when using vitest
I'm using vitest to do some unit tests in my vue application.
I've written some tests but they fail with the error message: 'TypeError: default is not a function'.
But I do not use a function called default() in my code.
import getInfo from…

Florian
- 45
- 1
- 4
4
votes
1 answer
ReferenceError: computed is not defined on Vitest test suite
Description
I'm migrating test suites from Jest to Vitest.
But i've a problem when i run test suites, an error occurs when a component has a computed property.
The common error is :
ReferenceError: computed is not defined
-…

superdunck
- 3,088
- 1
- 3
- 22
4
votes
0 answers
Why does `userEvent.click` not trigger a form submission with Vitest and React Testing Library?
The following test runs and passes just fine when using Create React App out of the box.
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import App from "./App";
describe("Update the…

CodeFinity
- 1,142
- 2
- 19
- 19
4
votes
1 answer
How would definePageMeta will be Mocked in Vitest?
I was trying Vitest to write UTs for my app which has Nuxt on the top of Vue.
But I am getting definePageMeta as undefined when trying to mock test.vue.
Here is my component test.vue -