【问题标题】:Buefy error when testing with jest - vuejs用 jest 测试时出现 Buefy 错误 - vuejs
【发布时间】:2022-01-18 03:17:57
【问题描述】:

我收到此错误:

    [Vue warn]: Unknown custom element: <b-taginput> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

关于这个测试:

import MultipleChoice from '@/components/MultipleChoice';
import Buefy from 'buefy';

const localVue = createLocalVue();
localVue.use(Buefy);


describe('MultipleChoice.vue', () => {
  let wrapper;
  beforeEach(() => {
    wrapper = shallowMount(MultipleChoice, {
      propsData: {
        choices: ['en', 'de', 'it'],
      }
    });
  });

  test('renders correctly', () => {
    expect(wrapper).toMatchSnapshot();
  });
});

测试本身通过,但此警告不断出现。

这是我的组件:

  <b-taginput
    v-model="value"
    :data="filteredData"
    expanded
    autocomplete
    open-on-focus
    clear-on-select
    field="display_name"
    icon="label"
    @input="update()" />

有人知道怎么回事吗?

【问题讨论】:

    标签: vue.js unit-testing jestjs buefy


    【解决方案1】:

    我想通了。缺少什么:

    import MultipleChoice from '@/components/MultipleChoice';
    import Buefy from 'buefy';
    
    const localVue = createLocalVue();
    localVue.use(Buefy);
    
    
    describe('MultipleChoice.vue', () => {
      let wrapper;
      beforeEach(() => {
        wrapper = shallowMount(MultipleChoice, {
          propsData: {
            choices: ['en', 'de', 'it'],
          },
          stubs: {
            transition: false,
            'b-taginput': true
          }
        });
      });
    
      test('renders correctly', () => {
        expect(wrapper).toMatchSnapshot();
      });
    });
    

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-17
    • 2020-09-11
    • 2019-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多