831 questions
1
vote
0
answers
2k
views
Testing event triggered when typing text in a textarea with Vitest and Vue Test Utils
I am writing tests with Vitest and Vue Test Utils, but I am having a problem with one of the tests where I want to test the invocation of my reflectInput function when text is typed into the input. ...
0
votes
1
answer
7k
views
How to check if component function have been called using Vue3, Vitest, and Vue Test Utils?
I have a component written in Vue 3 and script setup. Now I am trying to write a unit test for it, where I am instantiating a spy to check whether a function has been called.
I read somewhere that ...
6
votes
1
answer
8k
views
Issue with mocking Vue Router in Vitest
i'm learning Vue 3 using composition api, and im very new to Vitest aswell (i know it uses Vue Test Utils though).
So, in short i'm having a problem where I mock the Vue Router, trigger click on a ...
4
votes
1
answer
3k
views
How to unit testing by mock methods in for a Vue component using ViTest?
Unit test vue component by mocking methods using vitest.
MyComponent.vue
<script setup>
import { ref } from "vue";
const isSelectAll = ref(true);
const selectAllModel = ref(false);
...
3
votes
0
answers
1k
views
How to test a component can emit a file with Vue test-utils and Vitest?
I want to test that my "UploadFilesComponent" enables the user to:
Upload a file for later use
Emits that file to the root component
Using Vue-Utils and vitest I came up with the test ...
1
vote
1
answer
2k
views
Default slot inside Vue3 Component is not rendered in unit test using Vue Test Utils
I'm using Vue3 and Vue Test Utils in my unit tests and was successfully until arrived to this component with two slots inside, a default and a title (it's a copy and paste from the UIDisclosure ...
3
votes
2
answers
2k
views
vue-test-utils 3 setValue() not working on v-select from Vuetifyjs 3
I am currently trying to write a test using vitest/vue-test-utils for an app which uses vuetifyjs 3.
My issue currently is I am unable to set values through the v-select and v-autocomplete component (...
0
votes
2
answers
2k
views
Vitest and nuxt 3 form submit testing
I got a form in a nuxt 3 app with three input fields. Here is how the submit function looks like:
const submitForm = async () => {
try {
await $fetch("/api/contact", {
...
0
votes
1
answer
737
views
using querySelector in vue/test-utils
For testing, if a list is correctly rendered from an array prop I need to loop through the created items and see if inside data are ok. But I can't use querySelectorAll.
The problem is I can't use ...
5
votes
0
answers
1k
views
Vue-Test-Utils (Vitest) doesn't recognize Nuxt useRouter as a function
I am using Nuxt 3 on the current project at work. We just started writing tests (this is my first time doing that). I'm trying to test a component which has Nuxt useRouter and my basic test fails ...
1
vote
1
answer
2k
views
Vue.js testing - Renders error message TypeError: $setup.t is not a function
I use Vue.js 3, setup syntax, typescript and vue-i18n. For the testing I use vitest and Vue Testing Library. I try to mock i18n's t function, but looks like component doesn't see it. How can I solve ...
1
vote
1
answer
101
views
Shopware 6, jest test with vue-test-utils: unexpected behaivor on render template
This is fragmented/fantasy code to describe only the relevant passages
tests/my-component.spec.js
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import ...
0
votes
1
answer
271
views
Shopware 6, jest test: [vuex] module namespace not found in mapState():
My component test failed by commit to a custom state store with:
[vuex] module namespace not found in mapState(): MyComponentStore/
The component itself works as expected.
The codes:
tests/myComponent....
0
votes
1
answer
53
views
can't passed a vue js unit test made with jest
I have a vue.JS component in which, when mounted, executes a function getIngredients :
mounted() {
if (this.cocktail) {
this.getIngredients();
}
}
I have a unit test that won't pass :
it('...
0
votes
0
answers
77
views
Jest mock return value of inner function of exported var
report.api.js:
export var reportAPI = (function() {
function getIsProjectLeader() {
....
}
return {
getIsProjectLeader: getIsProjectLeader
};
}
workerReportForm.vue:
created() {
...
0
votes
1
answer
1k
views
Testing event emitted from child component with Vitest & Vue-Test-Utils
I want to test if "onLogin" event emitted from child component will trigger "toLogin" function from parent correctly.
Login.vue
<template>
<ChildComponent
ref="...
2
votes
0
answers
4k
views
How to mock a computed property in Vue 3 unit test?
I want to migrate jest unit tests from vue 2 to vue 3. But I'm stuck with mocking up computed props.
I got a lot of vue-2 unit tests written like this:
const wrapper = shallowMount(FooComponent, {
...
5
votes
0
answers
2k
views
How can test watcher in vue with vitest and vue-test-utils?
I am trying to create a unit test that covers this portion of my Vue component code.
const length = ref(sizes.value[0] ? sizes.value[0].value : 0)
watch(
() => length.value,
(newLength: number) ...
0
votes
1
answer
640
views
How to mock the route object in Vue 3 composition?
I'd like to mock the route object to prevent test failures like TypeError: Cannot read properties of undefined when accessing route.x.
I tried:
const route = { fullPath: '/', path: '/' };
const ...
1
vote
1
answer
352
views
How to bypass test coverage for external/dependency vue components?
We have two vue3 projects. Project 1 has some components that use components from Project 2 as imported dependencies.
In Project 1, MyComponent.vue:
<template>
<Project2Modal> Some html ...
4
votes
1
answer
8k
views
How to simulate a <select> element in Vitest / vue-test-utils in a Vue.js project
I am trying to simulate choosing an option in a <select> element in my Vitest test. The simulated selection should set the value of the ref that is bound to the <select>'s v-model. As you ...
2
votes
1
answer
1k
views
How to test Vue 3 component with Pinia store in it
I started to learn testing, but have not yet achieved much success in this. I'm trying to write a mock test for a component, but I'm getting an error
Test suite failed to run
Cannot find module '...
2
votes
0
answers
661
views
Vue3 Element Plus not rendaring the props inside the imported element when testing with the vitest
I have a very basic component called
ConfirmModal.vue
<template>
<el-dialog v-model="dialogVisible" :title="title" width="30%">
<span>{{ content }}...
0
votes
0
answers
458
views
Jest - Vue test utils - How to assert callback function of window eventlistener?
Im trying to check if a function is being call when resize event fired.
"@vue/test-utils": "^1.3.3"
"vue": "^2.7.14"
"jest": "27.1.0"
...
4
votes
2
answers
6k
views
vue-test-utils + typescript type for wrapper.vm
sitting on a issue here. ever used typescript + vue-test-utils and tried to manipulate a value for the test like:
wrapper.vm.aCoolRefValueToManipulate = 'something much cooler'?
well i tried. and it ...