【问题标题】:How to fix this error [Vue warn]: Unknown custom element: <nuxt-link> in unit testing with Jest如何修复此错误 [Vue warn]: Unknown custom element: <nuxt-link> in unit testing with Jest
【发布时间】:2021-02-12 15:28:06
【问题描述】:

我在运行 npm 运行测试时遇到问题。错误是

 [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();
  });
});

谁能帮帮我?

【问题讨论】:

    标签: vue.js nuxt.js


    【解决方案1】:

    您可以在创建实例时stub 子组件。有关存根组件的更多信息,请查看this link

    试试这样,这将解决您的警告!。

    const factory = () => {
      return shallowMount(SidebarCMS, {
         stubs: {
          'nuxt-link': true,
          'any-other-child': true
         }
       });
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-06
      • 1970-01-01
      • 2022-12-26
      • 2021-03-22
      • 1970-01-01
      • 2021-04-01
      • 1970-01-01
      • 2022-11-16
      相关资源
      最近更新 更多