Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
32 views

How to check called function. Vitest

I'm using Vitest. I have a main function checkForm, it can contain 2 or more functions with extensive logic. Therefore we can't extract logic from update and refresh const update = (): void => { ...
Jessika's user avatar
  • 37
0 votes
0 answers
19 views

How to perform basic testing with FormKit and Vue/Vite?

I'm trying to figure out how to test a basic FormKit form using Vue and Vite. The form has a text field and a button. If you enter text and then click the button, it should display in another field ...
techLiberty's user avatar
-2 votes
1 answer
136 views

toBeInTheDocument Matcher Not Working in Vitest with @testing-library/jest-dom

I’m having trouble using the toBeInTheDocument matcher with Vitest and @testing-library/jest-dom in my TypeScript project. Even though I have installed and configured everything correctly, I’m still ...
Akshat Parashar's user avatar
1 vote
0 answers
56 views

Unit test when there is style on the component

I'm checking out Svelte 5 and I have this simple component <script lang="ts"> let { name }: { name: string; } = $props(); </script> <h1> ...
Hey's user avatar
  • 197
0 votes
0 answers
10 views

Issue: slots Field in Typings for Svelte Component Testing

I am building a Svelte component library for my project and have run into several issues, particularly when trying to test components with slots. Here's the error I'm facing: Object literal may only ...
Józef Podlecki's user avatar
2 votes
0 answers
73 views

Astro 5.0.2 with vitest: getViteConfig and renderToSting of container fail

I just upgraded my Astro site to 5.0.2, but there seem to be breaking changes As per the docs, I use the following vitest config (root of project): /// <reference types="vitest/config" /&...
thomi's user avatar
  • 1,667
-2 votes
1 answer
99 views
+100

Code behaves differently in Vitest vs React

I have a simple test case: import {describe, it, test} from "vitest"; import {decodeBase64, hexlify} from "ethers"; describe('zapModule', () => { it('smoke test vitest', ...
Konstantin Pribluda's user avatar
0 votes
0 answers
35 views

Vitest Stuck when running in a Docker Container

I would like to run the Vitest Unit tests of my Nuxt application on Github Actions in a Docker container, but the tests do not start, but get stuck on the output to be seen below. I'm currently ...
Leo Gall's user avatar
0 votes
0 answers
26 views

How to mock multiple refs (and refs in general) in Nuxt?

I'm looking for a way to mock multiple refs (and refs in general) in Nuxt? I'm using Vitest and Nuxt test utils. About my Case: I want to test a SideBar.vue component. The component has multiple refs: ...
Leo Gall's user avatar
1 vote
0 answers
36 views

How to mock a typescript interface to test some use cases in a lib

I would like to have an interface populated only for test environment. Let say i have this interface in the lib code base // file MyInterface.ts export interface MyInterface {} And later in end user ...
zedryas's user avatar
  • 964
0 votes
1 answer
49 views

Vitest Async Mock Failing and Returning Undefined

I'm trying to write a unit test for an onMounted lifecycle hook for my Vue 3 component. I'm mocking the resolved value for an async call but it keeps returning undefined. As a result my last expect ...
Joe King's user avatar
0 votes
0 answers
120 views

Error: Vitest failed to access its internal state

I'm creating a utility package that exports multiple tools like eslint, playwright, vitest, react testing library etc, and I'm using rollup to bundle the package. However, when I install this package ...
Prajwal Kulkarni's user avatar
0 votes
1 answer
59 views

Vuetify cannot find useGroup injection when mounting a custom component in a test

Background: Vue3 app, using Vuetify, vitest, and vue-testing-library. Problem: I have a custom component whose template looks something like this: <template> <v-expansion-panel> ... ...
Andres Rosales's user avatar
0 votes
0 answers
29 views

Vitest and zustand Cannot read properties of null (reading 'useRef')

I'm trying to test with vitest a page with zustand But i'm getting this error : TypeError: Cannot read properties of null (reading 'useRef') ❯ useRef ../../../../../../node_modules/react/cjs/react....
Xero's user avatar
  • 4,176
0 votes
0 answers
12 views

How to mock Axios error response when using VueQuery

I am implementing VueQuery in my application. Now I am trying to write unit tests for this. The success case works fine, but when I mock an error case it seems to error is not being handled by ...
Ricardo de Vries's user avatar
0 votes
0 answers
28 views

MSW Mocking Readable Streams

I am trying to write a unit test by using the Mock Service Worker (msw) to mock an exceljs Passthrough Readable Stream, but I am getting this error: FAIL __tests__/excel.test.js > ...
superflux's user avatar
  • 137
1 vote
1 answer
33 views

Fastify Autoload with Typescript using Vitest

this is my scenario: I have a Fastify v5 server written in Typescript that I want to test using Vitest. This is my npm script vitest run --coverage --outputFile=results.xml Following what suggested ...
SamDroid's user avatar
  • 653
2 votes
0 answers
29 views

Read props of a Child component vue

Im currently writing tests for a Vue component (Calendar.vue) for that I need to get the array generated by the fillArray() function. My aproach is to read out the props of the Day.vue component but ...
Leander's user avatar
  • 21
0 votes
0 answers
35 views

Vee validate validation trigger issue in vitest

I am building a Vue.js 3 application using vee-validate for the application's forms. Especially I am using yup to define a schema and using the vee-validate composition API functions. I try to build ...
Cyril Auquier's user avatar
1 vote
0 answers
38 views

When I use global provides in Vitest, why does injection produce typescript errors

I'm converting from Jest to Vitest and I need to provide global variables to correlate things like user id during testing. setupTests.ts import type { GlobalSetupContext } from 'vitest/node'; export ...
MorganEngel's user avatar
0 votes
0 answers
28 views

Why is my vi.spyOn on a mocked function not recording calls in Vitest?

I'm testing a function called compareExcelFiles in Vitest, and I'm trying to spy on the readFile function it calls internally. Despite setting up the spy with vi.spyOn, the calls to readFile aren't ...
Édor Inc's user avatar
0 votes
0 answers
19 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", (...
Re9iNee's user avatar
  • 610
0 votes
0 answers
58 views

How to test custom hook with useEffect in React 18?

Hook: import { useEffect, useState } from "react"; const useIsClient = () => { const [isClient, setIsClient] = useState(false); useEffect(() => { setIsClient(true); }, []); ...
BrunoLM's user avatar
  • 100k
0 votes
0 answers
34 views

After the third line, the Vue file inside the pages folder code is not covered

After the third line, the code in the pages folder was not covered when selecting the v8 for coverage. How can I achieve this? I have provided the configuration and code changes in below. Vitest....
syed wajith's user avatar
0 votes
0 answers
33 views

Is there a workaround to mock window.location when using vmThreads/vmForks in Vitest?

You can configure vitest pool option to vmThreads/vmForks, however it seems like I can't mock window.location.href in this mode. Is there any workaround? How do you deal with tests that contain ...
Samuel Badru's user avatar
0 votes
0 answers
17 views

React and Vite whitescreen

Hi so I made this 3d portfolio and followed everything to deploy it to github pages. It works however I have an issue where my 3d models didnt load when i first click the link to the portfolio. My ...
Hobee's user avatar
  • 1
0 votes
0 answers
16 views

How do I access the mock instance type of a export mock?

Using vitest, it is possible to mock an exported module: import { myFn } from "myFn"; vi.mock("myFn", { spy: true }); See the second tip of the spyOn documentation. This mocks ...
papillon's user avatar
  • 2,013
-1 votes
1 answer
172 views

Vitest Error: No test found in suite <anonymous> [closed]

I using vitest for my testing environment, and after creating a new test, I'm getting the following error in my console: Error: No test found in suite I'm not sure what I'm doing wrong. Here's my ...
Jasperan's user avatar
  • 3,320
0 votes
0 answers
38 views

Tailwind CssSyntaxError Unknown word ">"

I'm trying to use vitest preview with tailwind I managed to generate the css file with tailwind tailwindcss -i ./src/styles/App.css -c tailwind.config.ts -o ./.vitest-preview/tailwind-output.css --...
Xero's user avatar
  • 4,176
-1 votes
2 answers
71 views

Why is function never called in test

I need help regarding a specific test. I have a Component, that is toggling the sound on and off in my project. The last test, with which I try to test if the e.prevenDefault gets called does not work,...
Mawin's user avatar
  • 9
0 votes
1 answer
31 views

Vitest not registering that spy has been run

Here is my view component: <template> <begin-adult-app-form :form-status="formStatus" :form-submitted="formSubmitted" v-on:form-valid=&...
Joe King's user avatar
0 votes
1 answer
23 views

import not understood by test, resolve error thrown

When I run the test getting the error as: Error: Failed to resolve import "@/components/card/LoadingCards" from "app/page.tsx". Does the file exist? Plugin: vite:import-analysis ...
3gwebtrain's user avatar
  • 15.3k
0 votes
1 answer
38 views

Unit tests using vue/test-utils not working with component that uses async setup

Im trying to use tests on component that is rendered asynchronously. I have tried to create simple component with async title but the problem still persists. I have added suspense around the component,...
ersi's user avatar
  • 256
0 votes
0 answers
39 views

Vue 3 vitest useMouse composable test not working

I've reused the mouse tracker composable here: https://vuejs.org/guide/reusability/composables, adding a twist by binding the event to an element in order to track the mouse position relative to it. ...
Tinydev's user avatar
0 votes
1 answer
46 views

Mock Multer for multiple tests (vitest and Typescript)

I wanna test my route. The problem is that I can't mock "multer" multiple times with different content. My Test: import request from "supertest"; import express from "express&...
Flo's user avatar
  • 3,077
0 votes
0 answers
33 views

Why does mocking dynamic import return a proxy object

I have the following (simplified) code under test: export const loadCommand = async (fqdnPath) => { return import(fqdnPath); }; and a test of that dynamic import method: import { test, expect, ...
James's user avatar
  • 399
0 votes
0 answers
161 views

Can't setup MSW for testing with Vitest and React Testing Library

When running the test, I'm getting an error: Error: No known conditions for "./browser" specifier in "msw" package. But nor the test neither the component doesn't use MSW. The test:...
Boi Stance's user avatar
0 votes
0 answers
52 views

Why do I have several files with uncovered lines from 1 to N after upgrading our Vitest coverage provider from C8 to V8?

We recently upgraded our Vue app from Vitest 0.31.4 to 2.1.2, and part of that upgrade involved switching coverage providers from C8 to V8. We're having an issue where multiple files now have missing ...
NTaylor23's user avatar
0 votes
0 answers
47 views

Vitest not picking up my mocked environment variables when testing axios call

I've got the following function: import axios from 'axios' const apiKey = import.meta.env.VITE_KEY const apiURL = import.meta.env.VITE_URL const headers = { 'key': apiKey, 'host': apiURL.replace(...
gespinha's user avatar
  • 8,447
0 votes
0 answers
39 views

How to mock class implementation used in a another class using vitest

Assume I have 2 modules that defines Repo and Service classes. // src/Repo.ts export class Repo { find() { return "hello"; } } // src/Service.ts import { Repo } from "./Repo&...
srinesha's user avatar
2 votes
1 answer
123 views

Classname does not match in Vitest snapshot

We have a Vitest setup for Vite-based React project using MUI. When we create a snapshot of a component, the class part will have hashed classnames like the following: <div class="...
Erik Kránicz's user avatar
-1 votes
2 answers
63 views

Why should I mock a function instead of using the function itself to unit test?

I'm honestly confused about the goal of mocking certain functions when unit testing my app. I've seen articles suggesting I should mock everything I test, but also others suggesting I should avoid ...
gespinha's user avatar
  • 8,447
1 vote
0 answers
29 views

Unable to trigger handler's REST API call

I am writing mocks responses (using MSW) for a test case for an API call when a page is rendered in vitest and I am unable to trigger the REST API call defined in a handler. Technically, if the API is ...
johnathan chan's user avatar
1 vote
0 answers
53 views

"Package 'graphql' support only TS versions that are >=4.1.0"

I'm builing a React-Typescript project, using Vite and Vitest as the unit test runner. I'm trying to run tsc -b && vite build but I got this error in the terminal > [email protected] ...
user1712638's user avatar
3 votes
0 answers
174 views

Vitest: Getting vi.mocked(...).mockImplementation is not a function after hot reloading

I using Vitest with React to make tests. I want to make a "simple" test, to simulate a basic user for my app. The test, when I run npm run test works, the problem is that if I make a change ...
Juan Andrés Romero's user avatar
0 votes
0 answers
24 views

SpyOn function does not recognize call after click event

I want to write a unit test for the function renderSetupPage with Vitest. Somthing with the mocked function startGame seems to be wrong, but I can't find the error. ../scripts/utils.js: export const ...
Jan Seipel's user avatar
0 votes
0 answers
43 views

Bcrypt compare mocking issue for unit testing in Nestjs

This is my authService code and i am trying to unit test with vitest this block async validateUser( email: string, password: string, ): Promise<User | UserToSetupAccountDto | null> { ...
Sena Kaplan's user avatar
0 votes
0 answers
36 views

Vuejs Test with Vitest fails when I use mock

I am implementing unit tests for my application, but when I try to mock a library that I imported into one of my components, the unit test fails with the following message. Failed to parse source for ...
J Daza's user avatar
  • 1
0 votes
1 answer
91 views

Vitetest / Vite / Vue create test objects for controls that don't generate error: Cannot read properties of null (reading 'createComment')

I would like to add some tests that actually try to load Popup.vue and ToolTip.vue in my project. The source code is in git at: https://github.com/geewhizbang/gw-popup It's not that the popup doesn't ...
GeeWhizBang's user avatar
1 vote
1 answer
189 views

BeforeEach not being executed in Vitest (Node.Js unit tests)

I'm writing unit tests for a Node.js module in Typescript, using Vitest. In one of the tests, the function that I'm testing is supposed to call another function (in a different module), so I've ...
Maya's user avatar
  • 77

1
2 3 4 5
19