J
J
jekanok2020-01-27 14:52:03
Vue.js
jekanok, 2020-01-27 14:52:03

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.

....
Who knows how to solve this problem?
Thanks for the answer!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Yarkov, 2020-01-27
@jekanok

Or import element-ui somewhere in setup.js (like this):

import Vue from "vue";
import ElementUI from 'element-ui';

Vue.use(ElementUI);

Or make stubs in the test:
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)
  })
})

A
Alex, 2020-01-27
@Kozack Vue.js

You need to call usebefore your tests. For example like this

import { createLocalVue, mount } from '@vue/test-utils'
import ElementUI from 'element-ui';

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

And then pass the instance to the test
const wrapper = mount(register, {localVue})
See the documentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question