[Vuejs]-Vuetify Could not find defaults instance

-1👍

It took me forever to find the solution: IconOptions type is wrong. Replace defaultSet with defaults in the icon options:

icons: {
  defaults: 'fa',
  aliases,
  sets: { fa, mdi }
}

0👍

I had the same error when trying to configure a unit test using Vitest and Vuetify.

I’ll leave my solution here in case others come here too. I was able to solve my error by creating a new vuetify plugin in my test case file.

// test/helloworld.spec.ts
import { mount } from '@vue/test-utils'
import { expect, test } from 'vitest'
import { createVuetify } from 'vuetify'
import * as components from 'vuetify/components'
import * as directives from 'vuetify/directives'
import HelloWorld from '../../src/components/HelloWorld.vue'

const vuetify = createVuetify({
  components,
  directives,
})

global.ResizeObserver = require('resize-observer-polyfill')

test('displays message', () => {
  const wrapper = mount({
    template: '<v-layout><hello-world></hello-world></v-layout>'
  }, {
    props: {},
    global: {
      components: {
        HelloWorld,
      },
      plugins: [vuetify],
    }
  })

  // Assert the rendered text of the component
  expect(wrapper.text()).toContain('Components')
})

Leave a comment