831 questions
3
votes
0
answers
901
views
Vue test coverage with Jest only checks imports
I'm testing my vue.js 2 project with jest and vue-test-utils, the test works fine, but I've a problem when I try to measure the coverage of .vue files.
The problem is that when I execute jest --...
3
votes
1
answer
3k
views
vue-test-utils, jest; ReferenceError: Request is not defined
I'm making a POST API call using ES6 Request() constructor in my vue.js application. The implementation works fine but my test suite (I'm using Jest with vue-test-utils) fails with the below error:
...
3
votes
0
answers
702
views
Test disabling of button using Vue Test Utils
How do you test a button's disabled attribute changing in vue test utils? The disabled attribute of the button depends on isFormValid and isFormModified. I've tried setting them to both true in my ...
2
votes
1
answer
3k
views
Check if type of emitted variable matches custom type
I am testing some Vue 3 components with jest and expect to get an emit when a button is clicked. Now I want to check if the object emitted matches a custom type I created in a different file.
e.g.:
//...
0
votes
1
answer
2k
views
Vue & Jest - How to test a method with parameters? With vue/test-utils NOT jest-dom
After a lot of research I was finally able to test an method with the follow code
it('should call myFunction - on Desktop', async () => {
const mockMethod = jest.spyOn(myComponent.methods, '...
1
vote
1
answer
823
views
RouterLink does not render in the test (Vue test utils)
I am trying to test vue-router links but the RouterLink does not render, causing the error Cannot call text on an empty DOMWrapper.
Test:
const mkroute = { params: { test: "a" } };
const ...
2
votes
2
answers
1k
views
vue/test-utils failed to trigger events on quasar q-input
Code sample as below:
vue/test-utils failed to trigger events on quasar q-input. I am trying to write a unit test using vue/test-utils and using quasar framework. What I am thinking to test is "a ...
0
votes
0
answers
578
views
vue-test-utils | TypeError: s.split is not a function
I try to run a test with vue-test-utils, including a component that has a mixin included, which has a function using split() on a string. The test looks like this:
describe('adminExample.vue Test', () ...
1
vote
1
answer
2k
views
Vue3: Testing load state fails in async function inside 'onMounted'
I'd like to test that a loading placeholder is displayed, while data from the server is fetching inside onMounted hook. Here is the component I'm testing:
<template>
<section class="...
1
vote
2
answers
3k
views
How to test transition function in Vue 3 test utils?
I have a problem testing transiton functions with jest and vue test utlis. This is my component code:
<div class="disclosure">
<button
class="label"
...
0
votes
1
answer
486
views
Testing call to other functions within the same component using nuxt.js and jest
I'm trying to write a test that tests the various method calls to other methods within the same file. So far, I've written tests for two different methods, one passes, one does not.
async ...
0
votes
1
answer
891
views
Rethrowing an error causes vue warning in jest test
I've got a vue application which exists of a page component and a nested child component, which makes a async post-request. If the request is failing, an error is thrown, which is propagated to the ...
3
votes
1
answer
1k
views
How to test @InjectReactive() of Vue-Property-Decorator on vue-test-utils?
I am not sure how to provide the inject-reactive data when I mount the component. I don't need the exact solution, just a hint would be much appreciated.
Here is my parent component:
@Component
export ...
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 ...
1
vote
0
answers
1k
views
Do I have to await .vm.$emit()?
I have a Vue 3 application and use vue-test-utils for testing.
I also use web components. One of the components is an input element that implements an inputChanged event that is triggered in case the ...
2
votes
0
answers
1k
views
How to pass vuelidate object with props for jest test?
I have several components inside each of them have fields that are validated with vuelidate. All field validation rules are described in the parent component wrapper in the child components, I pass ...
1
vote
0
answers
852
views
Unit testing nuxt fetch hook
I'm trying to unit test with Nuxt. Everything's going smoothly, but my problem lies with unit testing fetch. It seems that since this.$axios isn't a library (well, it is, but is injected to the ...
5
votes
3
answers
11k
views
Testing vue3 computed properties with TypeScript SFC
I am trying to write a test, using vitest, to assert a computed property in a vue3 component that is defined with script setup.
Consider a simple component:
// simple.vue
<script lang="ts"...
0
votes
0
answers
401
views
Get sibling component in Vue test utils (Vue 3, Composition API)
I'm currently exploring unit testing and Vue test utils particularly. I have an external library (vue-toastification) that shows a toast message when something occurs. I'd like to test that this toast ...
0
votes
2
answers
3k
views
Update text field in vue test utils (jest) not working
Hi i am new in jest and unit testing. i want to ask how to set value text input using vue test utils.
shortly I have custom component for text input, its my code
<input
v-model="...
0
votes
0
answers
1k
views
get value v-model(vue bind) after trigger click component using jest
i am so confused what happens with my code. i am new in jest and unit testing, while developing i use bootstrap-vue, nuxt and vue test utils (jest) for unit testing.
Shortly, i have custom component (...
1
vote
1
answer
507
views
how to mock socket.io-client with vue-socket.io-extended using vue test utils
this is how I integrate socket io client from vue main.js
import socketIoExt from 'vue-socket.io-extended'
import socketIo from 'socket.io-client'
Vue.use(socketIoExt, socketIo('http://192.168.1.1:...
1
vote
0
answers
281
views
How to implement or introduce socket.io-client from vue test utils?
When I trigger a function that requests API from $socket.client.emit I received client undefined after running npm run test:unit. I used 2 package from Vue when using socket-io here's my code from Vue ...
0
votes
0
answers
1k
views
Vue/Jest unit testing Cannot read property 'shallowMount' of undefined
I have been following the Vue school guides on implementing Jest with Vue in order to start writing some unit tests.
So far I've installed jest, jest-serializer-vue, vue-template-compiler.
module....
1
vote
1
answer
497
views
vue.config.js configureWebpack not used in unit tests (vue 3)
In my vue config I have the following:
configureWebpack: {
resolve: {
alias: {
react: path.resolve(__dirname, 'composition/react'),
hooks: path.resolve(__dirname, 'composition'),
...