如何修复此错误 [Vue warn]: Unknown custom element: <nuxt-link> in unit testing with Jest
Posted
技术标签:
【中文标题】如何修复此错误 [Vue warn]: Unknown custom element: <nuxt-link> in unit testing with Jest【英文标题】:How to fix this error [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();
);
);
谁能帮帮我?
【问题讨论】:
【参考方案1】:您可以在创建实例时stub
子组件。有关存根组件的更多信息,请查看this link。
试试这样,这将解决您的警告!。
const factory = () =>
return shallowMount(SidebarCMS,
stubs:
'nuxt-link': true,
'any-other-child': true
);
;
【讨论】:
以上是关于如何修复此错误 [Vue warn]: Unknown custom element: <nuxt-link> in unit testing with Jest的主要内容,如果未能解决你的问题,请参考以下文章
安装 VueJS CLI 时如何修复 npm WARN deprecated 错误
如何修复错误“找不到此相关模块:* ./src/main.js in multi (webpack)-dev-server”在 npm run serve in vue3.x with typescr