919 questions
0
votes
0
answers
27
views
Angular 21 Vitest, FakeTimers and RxJS debounceTime
I could successfully migrate my Angular 20/Jasmine/Karma app to Angula r21/Vitest
All my tests are running correctly, except the ones that use debounceTime from RxJS
As a workaround for now, ny unit ...
Advice
1
vote
1
replies
100
views
Angular: Vitest vs Jasmine/Karma
I am a bit confused with the Angular testing landscape. I have seen that Vitest will become the new default, replacing Karma. The question I then have is what about Jasmine. Does Vitest replace only ...
-1
votes
1
answer
76
views
Alias import issues in Vitest
I'm trying to have Vitest + Storybook setup and the following is my vitest.config.ts:
import path from "path";
import { fileURLToPath } from "node:url";
import { defineConfig } ...
-4
votes
0
answers
52
views
How do I turn off automatic screenshots in Vitest browser/Playwright?
I am using Vitest in browser mode, with Playwright as the provider. Whenever a test fails, a screenshot of the failed test is created in __screenshots__/<filename>/<test-name>. I am unsure ...
12
votes
2
answers
14k
views
Vitest config doesn't detect jsdom environment
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/...
4
votes
3
answers
1k
views
Vitest importActual: Jest gets types, but Vitest gives "... is of type unknown"
I'm migrating from jest to vitest. In the process, I am converting these:
// Jest
const myLib = jest.requireActual("mylib.js")
to these:
// Vitest
const myLib = await vi.importActual("...
0
votes
2
answers
94
views
How to remove setTimeout in Vitest?
I have a function that allows users to register. After successful registration, the user is redirected to the home page (after 5 seconds). Before being redirected, the user receives a toast ...
-1
votes
1
answer
57
views
Accessing calls/args in a global mock with spied functions
In a large Vue 3 app, we have some helper modules that are imported into various components. One of these helpers returns the root node, which itself contains many other methods.
In the app calls to ...
0
votes
0
answers
19
views
Use MSW with a self-signed certificate for a specific domain
I have a Vite app and configured a domain - say https://abcd.io:5173 - as a domain and certificates are generated for this domain. Now I would like to use MSW for testing. But when I try to enable ...
0
votes
1
answer
90
views
Error running vitest with npm run test:ui: Error: listen EACCES: permission denied ::1:51204
I’m trying to run Vitest with the UI enabled using:
"scripts": {
"test:ui": "vitest --ui"
}
When I run it with:
npm run test:ui
I get the following error:
Error: ...
1
vote
2
answers
142
views
In `test.projects`, each subfolder is a project, but the parent folder is also treated as one, so tests run twice
I want to run Vitest tests in a monorepo. I'd like to distinguish between the tests of my different packages when running them, so I used the test.projects array in vitest.config.ts. To avoid listing ...
7
votes
2
answers
3k
views
Vitest in-source testing: Property 'vitest' does not exist on type 'ImportMeta'
I'm trying the in-source testing of vitest. Here is the example given by the doc:
if (import.meta.vitest) {
const { it, expect } = import.meta.vitest;
it('add', () => {
expect(1 + 1).toBe(2)...
-4
votes
1
answer
66
views
Use property from object as test name in test.for
When I use:
describe("ExtractDateFromText", () => {
test.for(scannedReceiptText)('Filename %s', async (expected) => {
const dateResult = dateFromRawData(...
1
vote
1
answer
2k
views
How to increase number of log lines?
When using vitest to test a UI, I'm trying to do a screen.getBy.. that fails.
When it fails, I see the rendered HTML as a log, but it cuts off abruptly so that I can't see the elements that actually ...
0
votes
1
answer
87
views
Cannot use GraphQLSchema [...] from another module or realm
I have this very persistent problem which is very strange to me. It actually happened in a larger project but I isolated it in a very minimal project setup and the error keeps happening, hopefully ...
1
vote
1
answer
51
views
Combine toMatchSnapshot and toBeCloseTo behavior?
In my snapshot, I have objects of the following format:
{
"meanElements": {
"Om": 2.2835713400168607,
"am": 1.3043985097733939,
"em": 0.166565,
...
1
vote
1
answer
2k
views
Assert for correct body with mock service worker
we got a Vue application which calls an api endpoint using vueuses useFetch. It is tested with Vitest and msw (mock service worker) to check our API calls. Our code looks like the following:
// api.ts
...
1
vote
1
answer
123
views
Snapshot for visual testing is not capturing entire component
I am using vitest with vitest-plugin-vis and playwright to perform visual testing in my Vite project. The issue I am facing is that the snapshots that are generated are only capturing part of my ...
1
vote
1
answer
60
views
importing enums from prisma returns undefined in testing environments
This problem happens in testing environments.
when I try to import an enum from @prisma/client it returns undefined...
import { DailyTip } from "@prisma/client";
describe("test", (...
11
votes
12
answers
21k
views
Vitest Error : React refresh preamble was not loaded. Something is wrong
I am new to testing and I was trying to use vitest for testing my mern social media app. looking for references to test a react component using vitest i found this article https://eternaldev.com/blog/...
2
votes
1
answer
3k
views
Disable vitest's timeout when debugging in vscode
When working on a test, I might run, and rerun it 100 times while stepping through in debug mode, refactoring and re-checking certain things, but vitest's default timeout period is only 5s, and vitest'...
0
votes
0
answers
56
views
ReferenceError: Cannot access '__vite_ssr_import_1__' before initialization for Zod discriminated union
I'm working on a Zod schema for nodes where each node got a unique ID, unique type and an array of child nodes. Because of that I created a helper function acting as a base schema for nodes
function ...
0
votes
2
answers
623
views
Cannot pass props object to React+typescript component
Sorry if this seems really obvious, but I've been trying to figure out for two days now. I'm writing a simple unit test in vitest that renders a component to screen and then calling screen.debug(). ...
155
votes
20
answers
85k
views
Vitest defineConfig, 'test' does not exist in type 'UserConfigExport'
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 ...
3
votes
1
answer
272
views
Invalid PostCSS Plugin found using TailwindCSS 4 and Vitest
I have a Next.js app that is running without any errors. However, I am using Vitest for my testing framework and when running a specific test (layout.test.tsx) it produces this error:
FAIL src/app/...