920 questions
0
votes
0
answers
37
views
Initializing service values before tests using Angular 21 and Vitest
I've just moved over to Angular 21 and started using Vitest.
I'd like to initialize one of my services before the tests starts.
So I added provideAppInitializer in src/test-providers.ts like so:
// ...
0
votes
0
answers
57
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
176
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 ...
0
votes
1
answer
47
views
How to fix ERR_INVALID_URL_SCHEME when initializing C# in WebAssembly in node.js?
While I was able to get my C# code running in the browser as WebAssembly, I get errors like this when trying to run any (vitest) unit tests that load the module that initializes .NET:
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯...
-1
votes
1
answer
91
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
63
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 ...
0
votes
1
answer
69
views
Vitest config for Laravel and Vue
I have a Laravel 12 project built with the Vue starter kit. By default, the project didn't have any frontend testing libraries. I want to add tests in Vitest. When I run vitest, I get the error: Error:...
0
votes
0
answers
58
views
Type error not caught in vitest.config.ts
When writing a Vitest config file in TypeScript, type errors don't seem to be caught. How to change that (and thus benefit from type checking if an option property is wrong)?
Here's an example vitest....
1
vote
0
answers
46
views
How do I specify to WebStorm the canonical definition of the Vuex store?
Problem
I have a Vue project that uses Vuex for state management. Parts of the Vuex store are often mocked in unit tests (Vitest).
When Vuex stores are defined in both the main production code and in ...
0
votes
2
answers
96
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 ...
0
votes
1
answer
121
views
How to avoid target.hasPointerCapture is not a function when testing Radix UI (shadcn) components with Vitest + userEvent?
I'm testing components built with shadcn/ui, which uses Radix UI under the hood.
When running UI interaction tests using Vitest and @testing-library/user-event, I keep getting the following error:
...
0
votes
1
answer
52
views
Mocking Vitest functions for testing Pinia storage
I am struggling adding mocked methods when testing a Pinia store's functionality. There is very little documentation relating to actually testing the stores themselves, as most Pinia's official ...
-1
votes
1
answer
68
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
0
answers
34
views
Vitest/JSDOM: Native <dialog> Not Opening in Tests Despite All Fixes (Lightbox Modal Component)
I'm working on my portfolio site, and learning how to write TypeScript and test scripts. I'm stuck resolving these errors:
RUN v3.2.4 /Users/sigma/Documents/Websites/Site/Site 5
❯ tests/lightbox....
0
votes
1
answer
99
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
154
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 ...
0
votes
2
answers
128
views
How to programmatically get vitest test name?
I have a vitest test in the following form:
beforeEach(async () => {
// ???
})
describe('Subject Under Test', () => {
test('should behave as expected', async () => {
});
});
How ...
-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(...
0
votes
2
answers
72
views
$effect “forgets” state change, test crashes with “Cannot read properties of undefined”
I’m trying to write a Vitest unit test for an auto-save feature in a Svelte 5 project.
The test sets meta.settings.autoSaveIntervalMs = 50 so the save cycle finishes quickly, but the $effect still ...
0
votes
1
answer
92
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 ...
-2
votes
1
answer
254
views
ESLint doesn’t recognize Vitest globals when using a separate tsconfig.test.json with types: ["vitest/globals"]
I’m trying to separate my TypeScript test configs for a Vite + React + Vitest project. The tsconfig.app.json and tsconfig.node.json files were created automatically by Vite; I only added my own ...
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,
...
0
votes
1
answer
93
views
`async` test of a Fastify backend with `@fastify/websocket` times out, but also finishes
I'm trying to test (using Vitest) a part of my Fastify app that uses @fastify/websocket (and transitively ws), but my tests keep timing out despite running to completion. Here's a relevant excerpt ...
2
votes
1
answer
38
views
How to have access to globals injected with rollup in Vitest
I'm currently working on an existing React app and have to add Vitest to it.
The problem I'm facing is that globals are injected using the inject function from @rollup/plugin-inject in my vite.config....
1
vote
1
answer
133
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
votes
1
answer
41
views
Having EBUSY: resource busy or locked, rmdir 'blablabla...\dist' when trying to run Nest project locally via VSCode [closed]
I was facing this exact error every time I tried to run a Nest project locally via VSCode and I didn't find anything related to it on the internet, so I'm gonna post a question and the answer I found ...
0
votes
0
answers
182
views
Cannot read properties of undefined (reading 'wrapDynamicImport'). Getting this error right after generating a new project and trying to run tests
I ran the following commands in sveltekit to create a new project
npx sv create ch_ui
I selected the following options
┌ Welcome to the Svelte CLI! (v0.8.20)
│
◇ Which template would you like?
│ ...
0
votes
0
answers
57
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
0
answers
257
views
Vitest giving TypeError: React.act is not a function with React version 19
I am using React version 19 with Vite and when run Vitest, it's giving error
FAIL src/components/UserPopover/UserPopover.test.tsx > UserPopover > calls only
onCancel when "Cancel&...
-1
votes
2
answers
267
views
Vitest : cannot find package 'rollup'
While trying to execute unit tests with Vitest through Yarn in my Angular app I have an error about 'rollup' package :
yarn run test
[INFO] failed to load config from xxx\angular-test\vitest.config.ts
...
0
votes
0
answers
30
views
ReferenceError: route is not defined when testing component
I'm trying to test a simple Inertia.js + React component using Vitest and React Testing Library. The component uses useForm() from @inertiajs/react and the route() helper function from Ziggy (Laravel)....
3
votes
1
answer
281
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/...
1
vote
1
answer
1k
views
vitest fake timers and nested setTimeout
I have code in which setTimeout is called repeatedly. Essentially the callback of one setTimout sets another one and so forth. I’d like to test the delays with vi.useFakeTimers() so that the code is ...
0
votes
0
answers
58
views
Getting "SyntaxError: Cannot use import statement outside a module" when using Nest, Typeorm, Vitest and SWC
I recently experienced a memory leak in my jest with ts-node tests in my Nestjs project. After debugging, all evidence pointed towards jest being the issue so I started to migrate to vitest, following ...
0
votes
1
answer
77
views
Can an inappropriate callback be passed to waitFor?
I was going over Road to React (the book by Robin Wieruch), and I encountered a confusing piece of code. The code is on the Testing chapter, page 227:
describe('App', () => {
it('succeeds ...
0
votes
1
answer
171
views
Even when the threshold is not met, the vitest test coverage doesn't fail
i'm using Vitest test coverage and setting thresholds for the script to fail if the threshold values are greater than coverage values but it doesn't do anything. I have no idea what I'm doing wrong ...
0
votes
0
answers
35
views
Test Contentful composable with useNuxtApp - function undefined
I have a Nuxt composable that fetches data from Contentful using the contentful client's getEntries function. It's working on the frontend of my website but when I run my tests i'm getting:
TypeError: ...
0
votes
0
answers
35
views
React testing equivocally passes - overiding the mvw using server.use(...) fails
I expected this test to fail, but it still passes. And i wonder how?
I mocked the MSW requests expecting it to use the data i passed from in the server.use(...) it doesn't. it even passed with a wrong ...
0
votes
1
answer
193
views
Vitest react wait for function in useCallback to be in ready state
I have the following hook:
function useWelcomeMessage() {
const { data, error} = useGetWelcomeMessage();
const printMessage = useCallback(async () => {
if (data) {
alert(data)
...
0
votes
1
answer
165
views
Quasar Vitest: How to set up i18n boot file for both the dev/prod and the test
The recommendation for i18n in Quasar is to add it to a boot file like this:
import { defineBoot } from '#q-app/wrappers'
import { createI18n } from 'vue-i18n'
import messages from 'src/i18n'
export ...
1
vote
0
answers
45
views
How can I test inquirer prompts in commander js action?
I created a CLI with commander.js and I have some prompts like inputs etc.
I want to test the prompts with unit testing, so for example to set a test value when a prompt is showing.
So for example in ...
1
vote
0
answers
104
views
Mocking components on the server side when running tests on a SvelteKit API using Vitest
I'm developing a SvelteKit application and I try to use Vitest to run some tests.
I want to test a simple API endpoint:
// src/routes/api/test/+server.ts
import { testService } from '$lib/server/...
0
votes
1
answer
77
views
oclif runCommand vitest test fails with command X not found
I have a few commands with oclif whose tests fail with vitest but pass with jest. I believe something is off with the mocking. This is the structure:
src/
commands/
foo-cmd.ts
tests/
...
3
votes
1
answer
375
views
How to mock page from $app/state in SvelteKit + Vitest unit tests?
this is my first post — I'm new to both Stack Overflow and SvelteKit. I'm trying to test a Svelte 5 Navbar component that conditionally shows links/buttons based on:
page.data.user — if the user is ...
1
vote
1
answer
160
views
How to mock $env/static/public with vitest?
I'm using an env variable MY_VAR that I use from $env/static/public
import { MY_VAR } from '$env/static/public';
export const myVar = MY_VAR === 'true';
I'd like to mock it in some tests, to support ...
6
votes
1
answer
2k
views
Testing error after upgrading @mui/x-data-grid to v8.1.0 – Unknown file extension ".css"
After upgrading @mui/x-data-grid to version 8.1.0, I started encountering the following error while running unit tests using Vitest in my ReactJS application
TypeError: Unknown file extension "....
0
votes
0
answers
158
views
How do you make static assets accessible under vitest?
I am writing vitest tests that need http access to files in the public folder, which will be under the base url at production. What is a good way to accomplish this? I was hoping to find a plugin ...
4
votes
0
answers
272
views
How to test useSuspenseQuery hook
Recently I read about new hook useSuspenseQuery provided in @tanstack/react-query v5.
Previously I have used useQuery and have written unit tests on it.
I am trying to write unit tests on ...
6
votes
0
answers
742
views
Why is Vitest taking too much time to run even a single test file?
My project folder structure is this:
-frontend
-src
-components
-__test__
-pages
-dialogs
- etc
in __test__ folder there are all the test cases for components like ...