Skip to main content
Filter by
Sorted by
Tagged with
155 votes
20 answers
85k views

Trying to setup vitest on an already existing vite (vue 3, typescript) project. My vite.config.ts looks like this: import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; export ...
WillD's user avatar
  • 6,842
38 votes
11 answers
42k views

I am trying to migrate my tests from Jest to Vitest. I have a test suite that uses the dotenv package to pull in my .env variables. I have this in my test suite beforeAll(async () => { vi....
Bebet's user avatar
  • 629
31 votes
2 answers
56k views

I want to mock an object method that throws an error but the test is always failing with these errors. I can't post the image yet but please check the link. It shows the test failing. throw new Error ...
Shu Pesmerga's user avatar
26 votes
4 answers
33k views

I'm starting out with Vite for a React application but unable to get jest tests working. I am trying to use Vitest with experimental ES module. I am getting: FAIL src/App.test.tsx [ src/App.test.tsx ]...
Michael Durrant's user avatar
22 votes
7 answers
27k views

I have started to replace Jest with Vitest for my unit test library in my Vue 3 App. I am trying to write unit test for a component that uses the vue-i18n library to translate text within it but when ...
Mac's user avatar
  • 1,177
20 votes
1 answer
16k views

I am woking on a Vite project using react framework. I write some test cases for my app using vitest when I run the test I see the following error FAIL tests/Reservations.test.jsx > Reservations ...
Engr. Umair Ul Isam's user avatar
17 votes
4 answers
46k views

The following is an abstraction of my problem and thus does not make too much sense: Given I have a simple utility callMethodIf that's returning the return of another imported method (blackbox). ~~/...
floriankapaun's user avatar
16 votes
3 answers
14k views

I have the following tsconfig configuration: { "include": ["tests/**/*.ts"], "exclude": [], "compilerOptions": { "composite": true, &...
coure2011's user avatar
  • 42.8k
15 votes
1 answer
35k views

How do I get variables defined in my setup files to work in my test files? Setup files: var lol = 'lol' test: describe("test", () => { it("test lol", () => { expect(...
Harry's user avatar
  • 55.4k
15 votes
0 answers
3k views

I am using Vitest, Vite and jest for my testing. I am trying to extend the built-in Vitest matchers with @testing-library/jest-dom/matchers. I setup Vitest using the examples in this article, and ...
Sasha Komolkin's user avatar
13 votes
2 answers
15k views

Running npm init vue@latest with the following setup generates a Vitest spec file inside the src directory. I'm wondering why Cypress e2e tests have a seperate directory and Vitest unit tests are ...
user avatar
13 votes
1 answer
13k views

Trying to migrate some old TypeScript code from CRA to Vite, and getting stuck on a problem with Vitest. The project has dependencies like this: my-project (ESM) depends on: lib1 (CJS) depends ...
usethe4ce's user avatar
  • 24k
12 votes
1 answer
11k views

When I mock vue-router with Jest, and want to mock the return value of an internal method, TypeScript doesn't understand that the inner method has become a mock, and can be treated as such. For ...
Liam Arbel's user avatar
12 votes
5 answers
13k views

Adding 'jsdom' to vite.config.ts brings the following error: No overload matches this call. The last overload gave the following error. Argument of type '{ plugins: PluginOption[][]; test: { ...
Harry Chaklader's user avatar
12 votes
2 answers
14k views

I'm in a Vite/React/TypeScript application and I'm configuring my first test with Vitest. When I run my Button test (yarn vitest), I get this error: packages/frontend/src/components/Generic/Button/...
tomakazub's user avatar
  • 367
11 votes
1 answer
11k views

I created a new Vue project via npm init vue@latest ( with vitest ). Inside ./src/components is a __test__ directory containing a component unit test. Is it intended to create another __test__ ...
user avatar
11 votes
1 answer
9k views

I'm basically trying to mock an external module in the same way for all my vitest tests, and it's surprisingly not trivial. In Jest, I would just create a __mocks__ folder at the root, and it appears ...
Daniel Geisz's user avatar
10 votes
5 answers
15k views

I have this Vitest test: import React from 'react'; import { expect, it, vi } from 'vitest'; import { render, screen } from '@testing-library/react'; import { StyledNativeTimePicker } ...
Chen Peleg's user avatar
  • 3,190
10 votes
1 answer
22k views

I have a method, in a class, that only executes its action when NODE_ENV === 'test'. Here is the test that I set the env to anything to test the failing scenario: it('returns Left on clearDatabase ...
leal32b's user avatar
  • 394
10 votes
2 answers
5k views

Is there any way to use different tsconfig file for vitest? I have a large project using vue-cli. Before converting it to vite based I first want to use vitest instead of jest. The problem is that the ...
coure2011's user avatar
  • 42.8k
10 votes
1 answer
7k views

According to the Vitest documentation, this is supposed to allow debugging of Vitest in visual Studio code. So I have the following in launch.json: { "version": "0.2.0", "...
GeeWhizBang's user avatar
9 votes
3 answers
16k views

I want to mock fs with vitest and I am successfully doing so, however I am using any to do so. Consider import { promises as fs } from 'fs'; vi.mock('fs') it('can mock', async () => { // ...
ajthinking's user avatar
  • 4,846
9 votes
2 answers
9k views

I want to test a component using the useNuxtApp composable. This is the component(MyComponent.vue): <template> <div class="flex justify-between"> <span>{{ $fmt(12) }}&...
Adri HM's user avatar
  • 3,210
9 votes
3 answers
6k views

I'm trying to setup vitest + @vue/test-utils but I can't test some components that use ref(Vue) or useCookie (Nuxt), I have the same problem with Pinia as well where I import globally 2 functions in ...
DevWizard's user avatar
  • 697
9 votes
2 answers
3k views

After doing successful MSW (Mock Service worker) setup for browser. Everything is working fine. Here is my setup files -> //handlers.ts import { http, HttpResponse } from 'msw'; const handlers = [ ...
Ankur Marwaha's user avatar

1
2 3 4 5
19