JestでVuetifyのcomponentsが読み込めないconsole.errorが表示される話


JestでVuetifyのcomponentsのerrorが出る

適当なテスト用のコードを書いて見るとテストはPASSするけどconsole.errorが吐かれる

console.error {path}
[Vue warn]: Unknown custom element: <v-card> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

解決: localVue.use(vuetify)

localVue.use(vuetify)を書き忘れていただけだったようです。

test/pages/index.spec.js
import Vuetify from 'vuetify'
import { mount, createLocalVue } from '@vue/test-utils'
import IndexPage from '@/pages/index.vue'
const localVue = createLocalVue()

describe('pages/index.vue', () => {
  let vuetify
  let wrapper

  beforeEach(() => {
    vuetify = new Vuetify()
    // これを追加
    localVue.use(vuetify)
    wrapper = mount(IndexPage, {
      localVue
    })
  })

  describe('template', () => {
    it('「Hellow World」の表示', () => {
      expect(wrapper.text()).toBe('Hellow World')
    })
  })
})