Questions tagged [vue-test-utils]

Helpers to render VueJS components in unit tests.

Toolset to make complete or shallow rendering VueJS components while writing unit tests. Can be run under Jest or Mocha test runners. See vue-test-utils.vuejs.org for details.

814 questions
8
votes
2 answers

Vue testing with jest and vue-test-utils fails to resolve components introduced through app.component()

Im currently trying to introduce testing to my Vue 3 Vite application. I am using jest and vue-test-utils for this. This is working fine, except when I try to mount components that contain my base components, which I introduce with…
stackmeister
  • 199
  • 1
  • 2
  • 10
8
votes
1 answer

How do you access Vue-Composition-API type refs & "data" within Jest tests?

I'm currently working on a legacy Vue project. We're using Vue 2.x w/ Typescript, with the Options API. I'd like to make the case to switch to the Vue Component API, and so far I think it's a really compelling case - except for one drawback. And…
8
votes
2 answers

Vue Testing (JEST): button.trigger('click') not working

Been reading up a lot of stackoverflow and github discussions, about vue jest having trouble with button.trigger('click'). I've been struggling over this issue for a few hours today, have to say I'm quite frustrated, and surprised how a simple…
dulerong
  • 231
  • 1
  • 3
  • 8
8
votes
3 answers

"[vuex] state field foo was overridden by a module with the same name at foobar" with deepmerge helper function in jest

I'm using a helper function to create a store inside my jests. The helper function uses deepmerge to merge the basic configuration with a customized configuration. This results in multiple console warnings [vuex] state field "cart" was overridden by…
user5582011
8
votes
2 answers

Vue, vuex: how to unit test a component with namespaced store and mocking?

I'm building a login component using vue, vuex and vuetify. I've decided to use a namespaced auth module in store and this is causing me the problem. I'm approaching this using TDD. My e2e test works. But I wrote this unit test (using a mockStore)…
8
votes
1 answer

How to manually update vue computed property in test

I have a component Foo with Vuex binding mockedVuexBinding (which is essentially a computed prop). I want to keep tests simple and don't want to mock the whole store. All vuex bindings I just replaced with computed stubs in test, like this: const…
Maksim Nesterenko
  • 5,661
  • 11
  • 57
  • 91
8
votes
2 answers

Mock mounted hook Jest testing unit

I am doing some unit testing for components. However, in some components, I have something running on the mounted hook that is making my test fail. I have managed to mock the methods that I do not need. However, I was wondering if there is a…
heyr
  • 5,514
  • 11
  • 34
  • 55
8
votes
2 answers

How to trigger a window event during unit testing using vue-test-utils

I've added 'attachToDocument', but I still can't trigger a keyup event on window. my dependencies' version: "@vue/test-utils": "^1.0.0-beta.29" "vue": "2.5.18"