For my unit testing of components using VueJS and Jest, I'm incorporating the Bootstrap Vue library for styling. To address console warnings regarding unknown plugins, I've set up a configuration file:
import { createLocalVue } from '@vue/test-utils'
import BootstrapVue from 'bootstrap-vue'
const localVue = createLocalVue()
localVue.use(BootstrapVue)
I've instructed Jest to utilize this setup before each test:
setupFiles: ['<rootDir>/tests/unit/setup']
To eliminate the console warnings, it's necessary to employ the localVue
instance when mounting the component in tests:
const wrapper = shallowMount(MyComponent, {
localVue,
propsData: { value: 'someVal }
})
However, transferring the localVue
instance created in the setup.js
to the test spec files seems challenging.
If I resort to:
import Vue from 'vue'
import BootstrapVue from 'bootstrap-vue'
Vue.use(BootstrapVue)
The process works smoothly, but relying on the Global Vue instance in Jest tests is discouraged.
Is there an efficient method to achieve this, or must I manually integrate the necessary plugins like Bootstrap Vue into every single test file?