Answer the question
In order to leave comments, you need to log in
How does vue test utils jest work?
I'm using prebuilt element.io components in a project and wanted to test the work done with vue test utils it's written in jest when I wrote the first test to try
import {
mount
} from '@vue/test-utils'
import register from '@/components/form-reg.vue'
describe('Register', () => {
const wrapper = mount(register)
it('имеет кнопку', () => {
expect(wrapper.contains('button')).toBe(true)
})
})
gave me an error: [Vue warn]: Unknown custom element: <el-row> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
Answer the question
In order to leave comments, you need to log in
Or import element-ui
somewhere in setup.js (like this):
import Vue from "vue";
import ElementUI from 'element-ui';
Vue.use(ElementUI);
import {mount} from '@vue/test-utils'
import register from '@/components/form-reg.vue'
describe('Register', () => {
const wrapper = mount(register, {
stubs: {
'el-row': '<div></div>'
}
})
it('имеет кнопку', () => {
expect(wrapper.contains('button')).toBe(true)
})
})
You need to call use
before your tests. For example like this
import { createLocalVue, mount } from '@vue/test-utils'
import ElementUI from 'element-ui';
const localVue = createLocalVue()
localVue.use(ElementUI);
const wrapper = mount(register, {localVue})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question