自定义 Vue 组件中的 BootstrapVue b-modal 组件在浏览器中正确加载。但是,当使用 mocha+mochapack 进行测试时,它会生成一个 Vue 警告,提示 b-modal 元素未注册。该测试使用已注册 BootstrapVue 的 localVue 对象。所有其他引导程序自定义元素似乎都正确加载,并且不会生成任何警告。
我尝试了各种方法,包括从“bootstrap-vue”导入 BModal 并将其直接注册为组件,但仍然出现相同的错误。
import {mount, createLocalVue} from "@vue/test-utils"
import MyCustomModal from '../js/MyCustomModal';
const localVue = createLocalVue();
import BootstrapVue from 'bootstrap-vue'
localVue.use(BootstrapVue);
describe('MyCustomModal', () => {
let wrapper = mount(MyCustomModal,{
localVue
});
it('the content is "this is the content"', () => {
expect(wrapper.find(".modal-content").text()).toEqual('this is the content');
});
});
自定义 Vue 组件:
<template>
<b-modal>
<div class="modal-content">this is the content</div>
<b-form>
my form
</b-form>
</b-modal>
</template>
<script>
export default {
data(){
return {};
}
}
</script>
测试正确运行并通过,但它输出 b-modal 元素的 Vue 警告。它不输出 b-form 的警告。