解决vitest +Vue Test Utils 组件中包含第三方组件时报 Failed to resolve component

黄良钵

分类: 程序开发 58 0

[Vue warn]: Failed to resolve component: a-descripttions
If this is a native custom element, make sure to exclude it from component resolution via compilerOptionns.isCustomElement
at <Index schemas= [

当我们测试组件中按需引入了第三方组件(ant-design-vue)时,单元测试会报Failed to resolve component

这里我们只需要在global中加入plugins: [antdv],相关代码如下:

import antdv from 'ant-design-vue';
describe('Descriptions', () => {
  test('renders properly', () => {
    const wrapper = mount(Descriptions, {
      props: {
        schemas: schemasList,
      },
      global: {
        plugins: [antdv], // 修改这里
      },
    });
    expect(wrapper.classes('cpn-basic-descriptions')).toBe(true);
  });
});
  • 0人 Love
  • 0人 Haha
  • 0人 Wow
  • 0人 Sad
  • 0人 Angry
ant-design-vue、component、vitest、Vue、Vue Test Utils、单元测试

作者简介: 黄良钵

打赏

博客站长,前端开发工程师

共 0 条评论关于 “解决vitest +Vue Test Utils 组件中包含第三方组件时报 Failed to resolve component”

Loading...