答案 0 :(得分:0)
如果问题仍然存在(我没有找到任何直接答案),请尝试“存根”应导入的组件。
组件
<template>
<div>
<dynamic-imported-component-one id="componentOne"></dynamic-imported-component-one>
<dynamic-imported-component-two id="componentTwo"></dynamic-imported-component-two>
</div>
</template>
<script>
const ComponentOne = resolve => import(/* webpackChunkName: "views/view-ComponentOne-vue" */ '../Components/ComponentOne.vue');
const ComponentTwo = resolve => import(/* webpackChunkName: "views/view-ComponentTwo-vue" */ '../Components/ComponentTwo.vue');
export default {
components: {
'dynamicImportedComponentOne': ComponentOne,
'dynamicImportedComponentTwo': ComponentTwo }
}
</script>
测试:
describe('SomeComponent.vue', () => {
const stubs = {
dynamicImportedComponentOne: '<h3>Stubbed component one</h3>',
dynamicImportedComponentTwo: '<h3>Stubbed component one</h3>'
}
it('test for SomeComponent', () => {
const wrapper = shallowMount(SomeComponent, { stubs });
expect(wrapper.find('#componentOne').exists()).toBeTruthy();
expect(wrapper.find('#componentTwo').exists()).toBeTruthy();
});
});
您无法测试ComponentOne / ComponentTwo的内容,但是无论如何都应该在单独的测试中完成。