vue.js - 如何修复此错误 [Vue 警告]:未知的自定义元素:在用 Jest 进行单元测试
问题描述
我在运行 npm 运行测试时遇到问题。错误是
[Vue warn]: Unknown custom element: <nuxt-link> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
边栏CMS.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
在创建实例时创建子组件。有关存根组件的更多信息,请查看此链接。
试试这样,这将解决您的警告!
const factory = () => {
return shallowMount(SidebarCMS, {
stubs: {
'nuxt-link': true,
'any-other-child': true
}
});
};
推荐阅读
- android - 开始输入时如何从 EditText 获取值?
- php - 如何显示帖子的评论?
- r - 你可以“保存” dplyr 函数供以后使用吗?
- python - 根据列表中的某些项目查找字符串的长度
- reactjs - Redux ToolKit:是否可以在由 createAsyncThunk 创建的一个操作中调度来自同一切片的其他操作
- c++ - 具有引用成员的默认复制分配运算符?
- firebase - 如何使用我存储在数据库中的文件名从 Firebase 存储中获取图像?
- r - 更改 R Markdown 图形宽度
- r - 循环 rstudio 的 aes_string 中的图例
- oracle - 在 oracle 12c 中手动授予权限