56 questions
0
votes
0
answers
52
views
Testing Bootstrap accordion in Vue component with Nuxt test utils failing
I recently upgraded my project from Vue 2 to Vue 3, so i'm just importing Bootstrap instead of using Bootstrap-Vue.
I want to test the accordion functionality using nuxt-test-utils and my test ...
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
1
answer
60
views
Vue Test Utils on async component always returning empty/undefined
I am updating my project from Vue 2/Nuxt 2 to Vue 3/Nuxt 3. As i've been doing this my tests have broken and i'm trying to resolve them but every way I try to shallowMount my component returns an ...
0
votes
1
answer
528
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>
... ...
0
votes
2
answers
832
views
PrimeVue InputNumber not updated using vue-testing-library fireEvent (vue3)
I'm using Vue 3.4, vue-testing-library 8.0.2 and vitest.
I can't get my ref updated when using PrimeVue InputNumber (v-model) component in my unit test (whereas it perfectly works when executed in my ...
0
votes
1
answer
1k
views
Unit testing vue 3 onErrorCapture life cycle hook
import { onErrorCaptured } from "vue";
import { TheLayout } from "@/components";
const snackbar = useSnackbar();
onErrorCaptured((err) => {
console.error(err);
snackbar....
0
votes
1
answer
1k
views
vitest/vue-testing-library - mock error -> What is the recommended approach?
I've been struggling with some tests for some time and I cannot find a proper way to make them work.
I use vitest, vue-testing-library and jest-dom when useful.
What I want is to be able to use ...
0
votes
0
answers
207
views
How to mock Vaadin components with Jest/Vitest in a Vue project
I'm currently working in a Vue+javascript project that uses Vaadin components.
I'm trying to test our code using vitest + vue testing library, but I'm having problems mocking the third party ...
2
votes
1
answer
526
views
How to make vue testing library recognize script setup?
So I have an existing project where I wanted to add testing suite with jest + vue testing library.
Added necessary libs and configs and jest basic calc sum test passes.
After that importing basic vue ...
1
vote
1
answer
1k
views
When using testing-library with Vue, what is the best way to confirm an element is hidden by v-show?
When using testing-library with Vue it is easy to check if an element is not present in the DOM.
For example when v-if for the element is false:
element = screen.queryByTestId("my-element")
...
1
vote
0
answers
84
views
Why does Jest throw an error when importing components from Vuetify inside node_modules folder
I decided to test my vue 3 project, in which I use vuetify components
How do I correctly test my components in which I use vuetify components?
When importing a component directly into the test, Just ...
1
vote
0
answers
499
views
Using Quasar plugins with vitest in vue 3 (compat) breaks tests
I have a Vue 3 project created with Vite and using @vue/compat. I recently added Quasar using the Vite Plugin. For my tests, I use Vitest and Vue Testing Library.
Everything works as intended, except ...
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
1k
views
Test assertions fail in vitest because vue component DOM is not updating after an axios request in a method
On a button click, the text in a div is supposed to be updated with data from an axios request. It works but the test fails (the text in the div doesn't get updated in the test). A basic ...
3
votes
1
answer
4k
views
Using vitest and testing-library is there a way to segregate component renders on a test by test basis?
I have a simple list component written in Vue3 that I am using to learn how to write automated test with Vitest and testing-library. However every test method seems to be rendered together, causing my ...
1
vote
0
answers
107
views
Vue Testlng Library and Child Components
I'm struggling to understand how I should be testing my parent/child components using the [Vue Testing Library][1].
I have a parent component called SavedCards which displays a child component (called ...
1
vote
0
answers
459
views
Vue Test Utils - It doesn't mount the component for the test and it still returns "Cannot read properties of undefined " in the terminal
After implementing the searchBar logic, my tests stopped working (even those that don't depend on this searchBar component), I tried to mount the Header component with shallowMount, but it doesn't ...
1
vote
3
answers
6k
views
Vue Testing Library: How to mock Vue component
I used React Testing-Library, but not Vue Testing-Library before https://testing-library.com/docs/vue-testing-library/intro/ and I don't want to use mount or shallowMount where I can provide a stub. I ...
2
votes
1
answer
3k
views
Testing Pinia changes in a Vue 3 Component Unit Test
I have a component in my Vue 3 app which displays a checkbox. The checkbox can be manually checked by the user but it can also be checked/unchecked as a result of a Pinia state change. I'm pretty new ...
4
votes
1
answer
771
views
VeeValidate4. How to test custom field Component which uses useField?
I tried to test my custom input component. But I don't know how to do it right, because I didn't find any info how to test it.
The only thing I found was from this Mocking Form and Field Contexts
My ...
1
vote
4
answers
8k
views
SyntaxError: Cannot use import statement outside a module { AXIOS }
Hello I changed my code from fetch to axios and when I run my tests I get this problem... Can anyone help me with that ?
SyntaxError: Cannot use import statement outside a module
> 1 | import ...
0
votes
1
answer
1k
views
Test vue3 components with vue-test-library and global components
I start to create unit tests for production app with use jest and @testing-library/vue and support libs. I make first test:
import vue from "vue";
import { render } from "@testing-...
0
votes
1
answer
2k
views
Cannot mount TipTap content in Vitest unit test
I have a vue component that contains a TipTap editor, which I am having problems testing. I am using Vitest with vue-test-utils.
This is my component:
<script setup lang="ts">
import { ...
4
votes
0
answers
2k
views
Simple checkbox test with vue unit testing library
Trying to work out something that I thought would be pretty simple!
I have a PrimeVue checkbox component on my page (and I'm using Vue 3, PrimeVue, vitest, @testing-library/vue and @testing-library/...
5
votes
1
answer
7k
views
Unit Testing Vue 3 Component that uses Pinia with Vue Testing Library
I am struggling to understand how I can test the rendering of items based on the results of a call to a Pina getter in my Vue 3 app (using the Vue Testing Library). An example of what I want to ...
5
votes
0
answers
1k
views
How to mock useRoute() in vue testing library
I ran into a problem when running a component test that has a line inside it:
const route = useRoute(). I get an error: Cannot read properties of undefined (reading 'path'). Here is the test:
describe(...
0
votes
1
answer
542
views
Mocking mixin in Vue Test libs
I'm having a couple of issues with my Vue test libs. I am trying to test a mixin. It requires setting the route and mocking a function. Here is my code
MIXIN
export const CampaignNotifier = {
...
0
votes
1
answer
294
views
Vue test blob object issue
I am trying to convert string to blob but I keep getting {} instead
const workingCSV = "Hey, hello, world,"
const localVue = createLocalVue()
const wrapper = shallowMount(...
1
vote
1
answer
1k
views
How to test component watchers with testing-library?
Struggling with testing-library and a Vue component with Vuex. This is the component, it has a watcher:
<template lang="pug">
div
</template>
<script>
import { ...
1
vote
1
answer
787
views
ESLint reports "screen not found in @testing-library/vue"
I'm trying to use @testing-library/vue and import the screen method and ESLint reports the following error: "screen not found in @testing-library/vue".
// The render function doesn't error ...
6
votes
2
answers
4k
views
ReferenceError: Vue is not defined | vuejs3, jest, @testing-library/vue and jest-environment-jsdom
I am unable to run simple jest tests in my vue3 project using @testing-library/vue and jest-environment-jsdom. When I run npm run test I get the following error
> [email protected] ...
2
votes
0
answers
263
views
Vue test can't find store in child components
I have a parent component and there are several child components. Some children use Vuex store. When I try to mount parent component like below in Vue test, I'm getting an error "Cannot read ...
3
votes
1
answer
5k
views
Testing with vitest and testing-library is not working: it is due to using the SFC Script Setup?
I'm new to Vue and especially with the composition functions. I'm trying to test a component that uses the script setup; however, it seems that it is not working.
The component is this one:
<...
0
votes
1
answer
1k
views
Adding Props to found components throw the mounted wrapper
I have a form that contains a selector reusable component like this
<template>
<div class="channelDetail" data-test="channelDetail">
<div class="row"&...
1
vote
0
answers
1k
views
vue 2 jest coverage is incorrect
I have setup unit testing using installation instructions from https://v1.test-utils.vuejs.org/
Tests are running properly. But the coverage is coming incorrectly.
In the report it is showing it has ...
0
votes
0
answers
661
views
Vue Formulate - Testing event emission on form button click using testing-library
I have the following component, using Vue Formulate
<template>
<FormulateForm @submit="onSubmit">
<button type="submit">Submit</button>
</...
0
votes
0
answers
159
views
How can I test Vue routes render right component?
How can I test the actual navigation that happens when a user clicks on a router link? E.g. I expect the linked component to be rendered but only the route changes, while the rendered component does ...
2
votes
0
answers
536
views
Fullcalendar.io show more link(dayMaxEvents) tests doesn't work in the vue testing library
I am using full calendar v5 and testing-library/vue for tests. I try to test show more events in the popover. But although I am giving events more than 4 the show more link isn't being loaded on the ...
0
votes
2
answers
3k
views
How can I trigger the 'blur' event while testing v-autocomplete using Vue Testing Library?
I'm writing a test for Vuetify v-autocomplete wrapper component which checks displayed error message on blur. However error output shows that input select remains open and base element has focus ...
0
votes
1
answer
2k
views
TypeError: _axiosMockAdapter.MockAdapter is not a constructor
I'm using vuejs, vue-testing-library, jest, axios, and axios-mock-adapter to test a component. I'm immediately running into the following error when trying to run my test:
TypeError: _axiosMockAdapter....
0
votes
0
answers
618
views
Vuejs testing library - how to write a test to handle axios request in "mounted" hook
I have a vue component that fetches data from an api in the "created" function. I'm just getting up and running using the following testing stack:
"devDependencies": {
"@...
16
votes
2
answers
17k
views
Using Vue Test Utils, how can I check if a button is disabled?
I'm testing a Vue component but I'm having trouble testing a button's disabled state. How can I access a button's disabled status in my tests?
I've tried using .attributes() but in this instance the ...
1
vote
2
answers
2k
views
Vue Testing Library won't rerender DOM when state changes
I have a component with a strait forward Edit button. The Edit button calls a method that sets isEditing to true.
There are a few input elements with v-if="isEditing", so I'm testing that ...
2
votes
1
answer
3k
views
Vue Testing Library, Child Component receives props
I'm trying to implement some Testing Library tests on a Vuejs app, but I can't figure out how to pass props to a component within the test.
For example, I want a unit test for a component that appears ...
1
vote
1
answer
603
views
Vue Apollo TypeScript: ApolloClient is missing websocket properties
I'm trying to set up a component test with Vue Testing Library and Apollo as described in their example.
import { ApolloClient, InMemoryCache } from '@apollo/client'
import { render } from '@testing-...
0
votes
1
answer
452
views
mock store getters inside Global Guard does not work
I created a global guard that uses getters from store.
I am trying to mock some getters from store for testing purpose. The problem is that mocking
does not work.
// router/index.ts
export function ...
0
votes
1
answer
4k
views
Can't test the input checkbox properly when the element is disabled using @testing-library/vue
I'm trying to create some tests for a checkbox component but looks like I can't make an assertion for an input[type="checkbox"] when is disabled.
In the first two blocks I'm testing if the ...
1
vote
1
answer
2k
views
@testing-library/vue :: testing emit an event on VueJS component using debounce
I'm trying to test an emitted event by an input field, which has a debounce on update method.
Without debounce, the test passed, without problems.
Here's a piece of the code.
import { render } from '@...
0
votes
1
answer
1k
views
Vue3/TS/Jest/testing-ligrary: can not run tests
I create project through vue cli with options: vue3, TS, JEST and add @testing-library/vue . my package.json looks like this
{
"name": "todo-app",
"version": "0....
2
votes
2
answers
4k
views
Vue3 Testing Library - vue-i18n not loading text
I can't seem to get the following example to work with vue3 and testing library.
https://github.com/testing-library/vue-testing-library/blob/main/src/tests/translations-vue-i18n.js
I've even tried to ...