你好 请教一个问题
Fearyao opened this issue · comments
Fearyao commented
vue unit test在项目中无法识别全局引入的组件
[Vue warn]: Failed to resolve component: el-input
lqsong commented
你用的是哪个版本?详细代码是什么?
Fearyao commented
使用的是vite+ts的版本
//执行操作 yarn test
//错误信息
[Vue warn]: Failed to resolve component: el-input
at <Anonymous ref="VTU_COMPONENT" >
at <VTUROOT>
//tests/unit/settingAuthProject.spec.ts
import { mount } from '@vue/test-utils'
import SettingAuthProject from '@/views/setting/auth/project/index.vue'
describe('SettingAuthProject.vue', () => {
it('listview', () => {
const wrapper = mount(SettingAuthProject)
expect(wrapper.vm.tableData.length).toEqual(5)
})
})
↓/views/setting/auth/project/index.vue
<template>
<div>
<el-input
placeholder="搜索"
prefix-icon="el-icon-search"
style="width: 150px; margin-left: 20px"
v-model="searchIpt"
></el-input>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
setup() {
return {};
},
});
</script>
<style lang="scss" scoped>
</style>
如果我单独引入的话 vueunittest就不会报错
import { defineComponent, reactive, ref, toRefs } from 'vue';
import {ElInput} from 'element-plus'
export default defineComponent({
components: {
ElInput
},
setup(){
//......
return
}
})
lqsong commented
因为你编写的是单元测试,和项目的开发、生产等环境是独立的,项目默认开发、生产的环境是全局引入了 element-plus
,但是你编写的单元测试没有全局引入 element-plus
,所以你独立引入也是好用的。