Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
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
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
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
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
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
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
37 views

VueWrapper error after typescript update to v5.5.2

When I update my project's TypeScript dependency to the version v5.5.2 from 5.4.5 it completely breaks my checks in test.ts files specifically with VueWrapper type, I use vitest. type error My usual ...
Jorge Luis Arencibia's user avatar
0 votes
0 answers
16 views

Testing a method in a Vue3 setup component with vitest [duplicate]

I need to make a test for a method in a VUE3 setup in a component and nothing I have tried works. Here is the simplified component: <script setup> function myFunction(number) { return number ...
Alex's user avatar
  • 89
2 votes
0 answers
206 views

Vitest VS Code extension displaying 0% code coverage

When running vitest run --coverage, I am seeing code coverage that accurately represents the coverage I have added via unit tests. However, when pressing the "Run Tests with Coverage" ...
natn2323's user avatar
  • 2,061
1 vote
1 answer
187 views

Vue 3 and Vitest focus input sets document.activeElement to HTMLBodyElement in test in composition API

Given a Vue 3 component <template> <input id="input" type="text" @focus="handleOnFocus($event)" /> </template> <script setup type="ts">...
mummybot's user avatar
  • 2,788
0 votes
0 answers
158 views

when debugging vitest unittest with vscode the Debug Console cannot access imported modules

I'm using vitest+vue3. When launching the debugger with launch.json pressing F5, in my Debug Console I can use modules imported by the script i'm debugging no problem. but when I want to do the same ...
codekoriko's user avatar
1 vote
0 answers
125 views

Vuetify v-form Form Validation Not Working in Vitest

I'm currently writing tests for a Vue3 + Vuetify website with Vitest. The website uses Vuetify components and one of the components I'm testing includes a v-form component. Here is the component code: ...
MerejzCV's user avatar
0 votes
1 answer
854 views

Properly mocking a composable function with vitest

In my Vue 3 app, I use the pattern of having a composable that contains methods that will handle fetching some data from various APIs. The reason they're composables rather than simple functions is ...
Sensanaty's user avatar
  • 1,086
0 votes
0 answers
200 views

Vue3/Vitest: Cannot read properties of null (reading '_vnode')

I have a fairly simple composable that renders a Vue component where we specify it on the DOM (defaults to the 'body'). Below is its entire code. export default function useComponent(Component, { to = ...
Riza Khan's user avatar
  • 3,108
0 votes
1 answer
577 views

How to simulate or Mock file selection with input[type=file] tag in vitest using vue test util

I have a component which is having an input tag of type=file. I want write a vitest test function, to simulate selection of file and assert its effects. Gemini gives below script but fails at line 6, ...
Kartik Kodag's user avatar
1 vote
1 answer
245 views

Vitest - ReferenceError: location is not defined

I'm trying to set up vitest for a Vue application that was recently converted from Vue 2 to Vue 3. I'm getting the following error, and have been unsuccessful in determining what the problem is. ...
piccy's user avatar
  • 366
1 vote
0 answers
329 views

How to mock i18n t() in vue3/nuxt3 compositionAPI with vitest?

Given the following component: <template> <WglResultList :show-sorting="true" :page-title="pageTitle" :sort-label="t('sortLabel')&...
user66875's user avatar
  • 2,610
0 votes
0 answers
116 views

Vitest error: SyntaxError: invalid arguments

I am trying to test a component that has vue-i18n translations in it, i have been using the plugin in all my tests however this particular component test gives me an error: SyntaxError: invalid ...
Farid Guzman's user avatar
0 votes
1 answer
481 views

Using Vue JS 3, vitest and happy-dom, how do I mount a component that requires an HTMLElement's clientWidth?

We have a component that does the following: Inside the template, has a div referred to as workspace when the component is mounted, inside the onMounted() it calls a method to calculate size the ...
Wimateeka's user avatar
  • 2,676
2 votes
1 answer
984 views

How do I test a Vuetify 3 select with vitest and vue-test-utils?

I have a v-select inside a form that I want to test with vitest and vue-test-utils. <v-select clearable :items="models" item-value="id" item-text="name" ref=&...
jaggarnaut's user avatar
0 votes
0 answers
147 views

How to Unit test errorCaptured Lifecycle Hook in Vue3?

I am trying to trigger error from child component so that errorCapttured hook will be triggered in main.vue Main.vue <template> <div class="main"> <q2-section class=&...
Arun Shetty's user avatar
-1 votes
1 answer
463 views

Testing Pinia store with setup syntax - how to mock computed fields?

Anyone have idea how can I test Pinia store with @pinia/testing and vitest if I made store with setup syntax. When I use createTestingPinia, I am able to mock computed fields, but actions calls could ...
Ika's user avatar
  • 9
0 votes
1 answer
94 views

How to reference HTML elements from ouside the App in Vue?

How to reference HTML elements outside of Vue's App tree? For example if you have the following index.html: <body> <div id="app"></div> <div id="quote&...
Alex's user avatar
  • 5,904
0 votes
1 answer
79 views

Why Vue's vue-test-utils test unit does not reach the proper route when using clicking a button?

I'm trying to write test for a form submission and no matter what I tried it failed. I was able to reduce the problem to a and App (App.vue), 2 components (TroubledLogin.vue and Info.vue) and a test ...
Alex's user avatar
  • 5,904
0 votes
1 answer
451 views

Can't get mock to execute in vitest

I'm trying to write a vitest test around a composable that reads and writes postMessage() for communication between iframes. The Vue docs say that if the composable relies on lifecycle hooks to mount ...
Ben's user avatar
  • 353
0 votes
1 answer
160 views

vue test utils v2 : cannot mock a global function

Brand new to vue testing and I'm trying to test a component that calls a global function this is imported in my app.js A simplified version of the component ConversationStatus: <script setup> ...
Ben's user avatar
  • 353
0 votes
1 answer
356 views

vue-test-utils v2: testing v-model value updates on keydown event

I'm brand new to Vue Test Utils and struggling a bit with the documentation on testing v-model updates. I'm using vite and so I've decided to use vitest I have an AutoComplete component with two slots ...
Ben's user avatar
  • 353
1 vote
1 answer
976 views

Vitest: Mocking composable inside of component test

I'm having a difficult time mocking a composable inside of a component. Looking to see if a function from the composable was called after a button was clicked. The composable is quite simple: export ...
Riza Khan's user avatar
  • 3,108
0 votes
1 answer
265 views

@vue/test-utils how to capture custom emit from child component

I'm trying to unit test a component that has a child component called <ButtonStandard> which captures a click event and emits a custom event called pressed. The parent component captures the ...
Ben's user avatar
  • 353
3 votes
1 answer
588 views

How to get vitest/v8 to ignore or correctly cover the script tag of vue component

All my vue component files start with <script setup lang="ts"> when using vitest with v8 for coverage, this line is not covered, and the branch is not covered. How to get the coverage ...
Ricardo van Laarhoven's user avatar
-1 votes
1 answer
252 views

How to mock __ function in Vitest?

I'm struggling to understand how to mock a localization function __() and even if that's the right solution to my problem. I am using Laravel for my backend and Vue for my front end and Inertiajs for ...
Ben's user avatar
  • 353
0 votes
1 answer
659 views

How in Vitest in Vue 3 to test haveBeenCalledWith example

I struggled with this a lot, even bought the course by testing Vitest in Vue 3 in Udemy, but nothing helps and works. But in the end I found a solution, may be it will be helpful for you.
Tatyana Molchanova's user avatar
0 votes
1 answer
373 views

How to test with Vitest in Vue 3 Suspense wrapper?

I tried a lot of techniques like await flushPromises(); or await nextTick(); or component.vm.nextTich() Nothing works!
Tatyana Molchanova's user avatar
0 votes
0 answers
516 views

how to populate initial state of pinia store in a unit test

I want to write a unit-tests for this a pinia store like : export const useMyStore = defineStore("MyStore", () => { // private state in the store const myProp = ref<string[]>([])...
Aref Takiden's user avatar
0 votes
1 answer
179 views

Component does not emit event after async vuelidate validation line

I'm using Vue 3.3.* and Vuelidate 2.0.*. I'm using setup + composition API, TypeScript and TailwindCSS. I'm creating unit tests using vitest and have a form in a component that I want to check if ...
Eric B's user avatar
  • 325
1 vote
0 answers
461 views

Vue3 and Vite: Codegen node is missing for element/if/for node. Apply appropriate transforms first

I creating a storybook app with components on based Quasar. While writing the tests, I got a problem with the slots (Vite). It is component's code: <template> <slot name="header" /...
student_it's user avatar
0 votes
1 answer
277 views

Pinia store loses reactivity in vitest

I am creating a simple calculator for my fullstack uni class. My vitest to check if the calculator display updates correctly when the pinia store with the display value updates, fails because it gets ...
Eric B's user avatar
  • 325
0 votes
1 answer
505 views

Mock @nuxtjs/i18n useLocalePath composable in unit test

I am trying to write test for Nuxt 3 component but I don't know how to mock useLocalePath() composable. Whatever I try I get TypeError: $setup.localePath is not a function AppHeader.vue <script ...
EstSiim's user avatar
  • 431
0 votes
0 answers
326 views

How to mock Tanstack library in Vue3 component test

I am writing test for a component that call an API with Tanstack this my component <template> <span v-if="isPending">Loading...</span> <span v-else-if="isError&...
morteza mortezaie's user avatar
0 votes
0 answers
174 views

NuxtUI form not firing on click event during unit testing with vitests

I have the following vue component <script setup lang="ts"> import type {FormSubmitEvent} from "#ui/types"; import {boolean, object, ref, string, type InferType} from "...
Christian's user avatar
  • 779
0 votes
0 answers
152 views

Testing a component with a chart

I'm working with vue 3.4.3 (option API) and vitest and I wan't to test a component containing a chart made with vue-chartjs, here is my test file : import { expect, describe, test, beforeEach, vi } ...
Drian's user avatar
  • 1
0 votes
0 answers
135 views

How to Mock Actions (negative and positive tests) to throw an error on api call in Unit Tests of Pinia stores with vitest?

I am new to Vitest and also Pinia, used with with VUE3 (options api), I am trying to test an action in pinia eg:- loadSettings(){ return return new Promise((resolve) => { getSettings() ...
roma's user avatar
  • 171
2 votes
0 answers
246 views

Vue3 Vitest isVisible() seems to be cached/stuck

I have a vue3 component which embodies a context menu. I have tested the component in the browser and it works fine. Also most situations work fine in vitest but when I use the .isVisible() check ...
SvT's user avatar
  • 25
0 votes
1 answer
299 views

How to test component that uses reactivity api in a vue3 using vitest

I'm using the simple state management with Reactivity API . I would like to test my component that depends on the store. How to mock the store? // store.js import { reactive } from 'vue' export const ...
user42488's user avatar
  • 1,395
0 votes
1 answer
1k views

Snapshot component testing with Vitest and Vuetify: failed to resolve component

I'm trying to perform snapshot tests with Vitest on a Vue 3 component with Vuetify 3. Here's my test: import { createVuetify } from 'vuetify'; import { describe, it, expect } from 'vitest'; import ...
Clément Picou's user avatar
-1 votes
1 answer
2k views

Register custom plugins globally in vitest

I have a lot of vittest files and i want to register the plugins globally for all test files. Currently most of the test files are mounting the VueWrapper as follows. const wrapper = shallowMount(...
MrSpt's user avatar
  • 1,018
1 vote
1 answer
3k views

Unable to run Vue component tests with Vitest

I have a project configured as follows: Vue version: Vue 3 Dev server: Webpack Testing utils: Vitest, Vue Test Utils I'm able to write and run tests for simple JavaScript functions, but when I try ...
user928112's user avatar
0 votes
1 answer
259 views

Why isn't my method being called after .trigger('click') using vue 3 composition api, vue test utils and vitest

I have a test which is checking to see if a function was called on click describe("Dropdown Component", () => { let wrapper; let selectedMeter = ref({}); let store let isBouncing =...
Imalizard Dawg's user avatar
-1 votes
1 answer
171 views

How to type variables defined in script setup for unit tests?

I'm using a reactive state in my component, defined in script setup: const state = reactive({ hello: 'world' }) It's accessible inside tests like so: wrapper.vm.state.hello = 'mad-world' ...
Artur Müller Romanov's user avatar