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 ...
0
votes
1
answer
36
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:
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯...
-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 ...
0
votes
0
answers
55
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....
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 ...
0
votes
1
answer
43
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 ...
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: ...
0
votes
2
answers
120
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 ...
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 ...
-2
votes
1
answer
233
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 ...
0
votes
1
answer
91
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 ...
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 ...
0
votes
0
answers
178
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
248
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&...
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)....
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
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
0
answers
34
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
1
answer
182
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)
...
1
vote
0
answers
44
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 ...
0
votes
1
answer
69
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/
...
1
vote
1
answer
153
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 ...
0
votes
0
answers
157
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 ...
5
votes
0
answers
721
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 ...