gpt4 book ai didi

vue.js - 如何修复此错误 [Vue 警告] : Unknown custom element: in unit testing with Jest

转载 作者:行者123 更新时间:2023-12-03 16:32:23 28 4
gpt4 key购买 nike

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

 [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();
});
});
谁能帮我?

最佳答案

您可以 stub创建实例时的子组件。有关 stub 组件的更多信息,请查看 this link .
像这样尝试,这将解决您的警告!。

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

关于vue.js - 如何修复此错误 [Vue 警告] : Unknown custom element: <nuxt-link> in unit testing with Jest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64603780/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com