Testing a Vue component using element-ui component Testing a Vue component using element-ui component vue.js vue.js

Testing a Vue component using element-ui component


I had a similar problem where element ui components were not recognized.

Had to import createLocalVue and ElementUI in the test file

import { shallow, mount, createLocalVue } from '@vue/test-utils'import Vue from 'vue';import ElementUI from 'element-ui';import Editor from '../src/components/layout/Editor'

and then

const localVue = createLocalVue();localVue.use(ElementUI);

and then

describe('Editor', () => { let wrapper beforeEach(() => {  wrapper = shallow(Editor, {localVue}, {    data : {      x: '0',      y: '0',    }  })})it('renders a vue instance', () => {  expect(wrapper.isVueInstance()).toBe(true);})


This looks like you're not importing the el-tree component properly. Vue is not translating the <el-tree> tag into a component, and is simply treating it as an html element instead.

Have a look at the element quick start page for different ways to import the components and make sure you've got things set up correctly.

Add some more details if you still have problems.


you should import element-ui in your test file.check this out: https://vue-test-utils.vuejs.org/guides/#applying-global-plugins-and-mixins.

however, I don't know how to import element-ui globally, so that I don't need to import it manually in every test file