VUE测试utils未检测到引导程序组件



我正在尝试测试使用子组件WarnOnUnsavedModal的组件。但是,我不是要测试子部分。

儿童组件使用 <b-modal>,在node_modules中,导入一个称为 bBtn的组件。

当我尝试运行测试文件时,它会失败以下消息:

import bBtn from '../button/button';
       ^^^^
SyntaxError: Unexpected identifier

我的测试文件:

import BootstrapVue, { bBtn } from 'bootstrap-vue';
import { mount, createLocalVue } from '@vue/test-utils';
import ComponentName from '../ComponentName.vue';
const localVue = createLocalVue();
localVue.use(BootstrapVue);
describe('ComponentName', () => {
    it('Has props', () => {
        const wrapper = mount(ComponentName, {
            store,
            createLocalVue,
            stubs: {
                ModalWarnOnSave,
                'b-btn': bBtn,
            },
            propsData: {
                resourceType: 'General',
            },
        });
        expect(1 + 1).toBe(2);
    });
});

我尝试在存根中添加这样的行:

stubs: {
    ModalWarnOnSave: true,
},

为什么不在这里捡起该组件?我尝试用Vue.use()换掉localVue.use(),无济于事。

我需要做什么才能完成此测试才能运行?我很高兴忽略引起问题的子文件。

尝试以下:

import BootstrapVue, { BButton } from 'bootstrap-vue'

bBtn不是b-button组件的导出名称。b-btn是vue.use'bootstrapvue时的别名组件。

请参阅https://bootstrap-vue.js.org/docs/components/button#importing-istividual-components

最新更新