[Vuejs]-Run unit test with Jest, Vue, Vuetify, and Pug

0👍

you can try:

wrapper.findComponent({name: 'v-btn'})

0👍

I guess I am late but I made it work.
I noticed you tried to find VBtn component by ‘v-btn’ class but VBtn doesn’t have it by default. That’s why I decided to stub it with my own VBtn that has ‘v-btn’ class.

import { shallowMount, Wrapper } from '@vue/test-utils'
import Login from '@/components/Login/Login.vue'
import Vue from 'vue'
import Vuetify from 'vuetify'

Vue.use(Vuetify)

let wrapper: Wrapper<Login & { [ key: string]: any }>
const VButtonStub = {
  template: '<button class="v-btn"/>'
}

describe('LoginForm.vue', () => {
  beforeEach(() => {
    wrapper = shallowMount(Login, {
      stubs: {
        VBtn: VButtonStub
      }
    })
  })

  it('should log in successfully', () => {
    console.log(wrapper.html())
  })
})

After test passed you will see in console log that stubbed component has ‘v-btn’ class. You can add yours and work with it like you want.

Leave a comment