在使用Jest进行Vue单元测试的时候,终端报错
Unknown custom element: - did you register the component correctly?
现象
在我们进行测试的部分出现了<router-link`>标签进行页面跳转,在测试的时候却报错。
解决方案:
在测试代码注入组件名称部分使用以下代码,component是你要测试的组件名称
shallowMount(Component, {
stubs: ['router-link', 'router-view']
})