Vue component register warning in unit tests with element-ui
In your tests, create a local Vue, call .use
in it and pass it to shallow
:
import { shallow , createLocalVue} from '@vue/test-utils'; // changed
import Vue from 'vue'; // added
import ElementUI from 'element-ui'; // added
import Component from '../Component.vue'
const localVue = createLocalVue(); // added
localVue.use(ElementUI); // added
describe('Component.vue', () => {
test('sanity test', () => {
expect(true).toBe(true)
})
test('renders button title', () => {
const wrapper = shallow(Component, {localVue}) // changed
Try to import the required module using Vue.use(Module)
in your .spec file.
// + Vue.use(ElementUI)
describe('Component.vue', () => {
...
})
You might get an error stating that you cannot import entire module because preventFullImport
setting is true
. To prevent it, modify your .babelrc or equivalent file and change your settings accordingly. All I did was preventFullImport: false
(personally for test cases only).