[Vue warn]: Unknown custom element: – When running jest unit tests

This is how I was able to get rid of the annoying warning: Include RouterLinkStub, eg.: import { shallowMount, createLocalVue, RouterLinkStub } from ‘@vue/test-utils’; Map NuxtLink stub to RouterLinkStub const wrapper = shallowMount(TestItem, { … stubs: { NuxtLink: RouterLinkStub } }) And in case you were checking nuxt-link text or something, change: const link = … Read more

The difference between Vue-Test-Utils’ “mount” and “shallowMount”?

What the documentation means by “stubbed child components” is that every components within the tested one will not be rendered. Instead, you will have a placeholder component. This prevent your tests to be parasite by other component’s behaviors. In my opinion, you should always shallow mount your components when doing unit tests, and simply mount … Read more

Vue-Test-Utils Unknown custom element:

Add the router-link stub to the shallow (or shallowMount) method options like this: const wrapper = shallow(TempComponent, { propsData: { temp }, stubs: [‘router-link’] }) or this way: import { RouterLinkStub } from ‘@vue/test-utils’; const wrapper = shallow(TempComponent, { propsData: { temp }, stubs: { RouterLink: RouterLinkStub } }) The error should go away after … Read more

How to Unit Test a Method in a Vue.js Component using jest

Calling component method The wrapper provides access to the component instance via its vm property, so you could call the method directly with: wrapper.vm.doSomeWork() Setting props The mounting options (passed to shallowMount() or mount()) include the propsData property that could be used to initialize the component’s props before mounting. You could also use the wrapper’s … Read more

tech