老师,可以出一期Switch组件的测试吗,不知道是不是因为内部使用了之前封装的Tooltip组件,测试的时候Tooltip组件的插槽部分一直不被mount,拿不到,dropdown那里也没法测,老师,怎么解决呢
import { describe, expect, test } from 'vitest'
import { mount } from '@vue/test-utils'
import Select from '@/components//Select/Select.vue'
import Tooltip from '@/components/Tooltip/Tooltip.vue'
import { Transition } from 'vue'
import { nextTick } from 'node:process'
describe('test::dl-switch', () => {
describe('basic', () => {
test('1.options', async () => {
const selectOptions = [
{ label: 'option1', value: '1' },
{ label: 'option2', value: '2' },
{ label: 'option3', value: '3' },
{ label: 'option4', value: '4' },
]
const wrapper = mount(Select, {
props: {
options: selectOptions,
modelValue: '',
},
global: {
stubs: {
Icon: true,
Tooltip: Tooltip, //这里去掉和加上结果是一样的
},
},
attachTo: document.body,
})
await wrapper.trigger('click')
await nextTick(() => {})
console.log(wrapper.html())
// const menu = wrapper.find('.dk-select__menu')
// expect(menu.exists()).toBeTruthy()
})
})
})
<div class="dk-select">
<div class="dk-tooltip dk-tooltip-light">
<div class="dk-tooltip__trigger">
<div class="dk-input dk-input--text is-suffix">
<!-- input -->
<!-- slots.prepend -->
<!--v-if-->
<div class="dk-input__wrapper">
<!-- slots.prefix -->
<!--v-if--><input class="dk-input__inner dk-select__tooltip-trigger" type="text" readonly="" autocomplete="off"><!-- slots.suffix --><span class="dk-input__suffix"><span class="dk-select__icon"><icon-stub icon="angle-down" border="false" fixedwidth="false" listitem="false" pulse="false" swapopacity="false" spin="false" symbol="false" inverse="false" bounce="false" shake="false" beat="false" fade="false" beatfade="false" spinpulse="false" spinreverse="false" class="dk-select__angle-down is-active"></icon-stub></span>
<!--v-if-->
<!--v-if--></span>
</div><!-- slots.append -->
<!--v-if-->
</div>
</div>
<transition-stub name="fade" appear="false" persisted="false" css="true">
<!--v-if--> //这里应该在我click之后mount dk-select__menu的,但是没有
</transition-stub>
</div>
</div>
我之前还打印了wrapper.emitted(),我发现触发了select的visible-chage事件,但是下面这里就是没有
<transition-stub name="fade" appear="false" persisted="false" css="true">
<!--v-if-->
</transition-stub>