vuejs / vue-jest

Jest Vue transformer
MIT License
746 stars 157 forks source link

Question: How to globally inject components with Vue3 and vue-jest? #405

Closed ccmetz closed 2 years ago

ccmetz commented 2 years ago

I'm using vue-jest (v5.0.0-0) with a Vue3 + TS project that uses Vuestic-UI as a components framework. I'm trying to figure out how to inject my Vuestic-UI components globally so that I don't get messages like the following when I try to run a unit test:

console.warn node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6799
    [Vue warn]: Failed to resolve component: va-button 
      at <Anonymous ref="VTU_COMPONENT" > 
      at <VTUROOT>

In the past with Vue2, I was able to use a setup file with something like this to import all of the components of the framework I was using (at the time it was Buefy):

import Vue from 'vue'
import Buefy from 'buefy'

// We need to register Buefy so that jest recognizes their components during our tests
Vue.use(Buefy);

How do I go about doing this with Vue3 and vue-jest? I haven't been able to find any documentation about it. Any help is much appreciated :)

EDIT: I just realized that @vue/test-utils is actually a more appropriate place for this question. Sorry about that! I'll close this issue and ask over there.