Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix this error [Vue warn]: Unknown custom element: <nuxt-link> in unit testing with Jest

Tags:

vue.js

nuxt.js

I have a problem running the npm run test. The error is

 [Vue warn]: Unknown custom element: <nuxt-link> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

SidebarCMS.spect.js

import { shallowMount } from "@vue/test-utils";
import SidebarCMS from "../layouts/SidebarCMS";

const factory = () => {
  return shallowMount(SidebarCMS, {});
};

describe("SidebarCMS", () => {

  test("renders properly", () => {
    const wrapper = factory();
    expect(wrapper.html()).toMatchSnapshot();
  });
});

Can anyone help me?

like image 200
ruby grv Avatar asked Oct 30 '20 06:10

ruby grv


1 Answers

You can stub the child components while creating instance. For more information about stubbing components, check out this link.

Try like this, This will resolve your warning!.

const factory = () => {
  return shallowMount(SidebarCMS, {
     stubs: {
      'nuxt-link': true,
      'any-other-child': true
     }
   });
};
like image 122
Naren Avatar answered Nov 02 '22 21:11

Naren