Files
Noblet Ouways 2f17df1209 style(eslint-config): newline before import type (#21036)
* perf: change to import-x

* feat: add rules

* chore: fix rule

* chore: fix

* chore: fix

* chore: fix

* style: `pnpm lint:fix`

* Revert "style: `pnpm lint:fix`"

This reverts commit db0116a288299c507e3cfc4d7a22e2207265d920.

* Revert "chore: fix"

This reverts commit 69c82a90c01525e38180be4c21e8ef5602512318.

* chore: fix

* style: `pnpm lint:fix`

* fix: lint

* chore: `pnpm format`
2025-06-16 15:37:12 +08:00

75 lines
1.7 KiB
TypeScript

import { nextTick, ref } from 'vue'
import { mount } from '@vue/test-utils'
import { afterEach, describe, expect, it } from 'vitest'
import { rAF } from '@element-plus/test-utils/tick'
import Popover from '../src/popover.vue'
import PopoverDirective, { VPopover } from '../src/directive'
import type { PopoverInstance } from '../src/popover'
const AXIOM = 'Rem is the best boy'
const _mount = () => {
const popoverRef = ref<PopoverInstance>()
return mount(
() => (
<>
<Popover
ref={popoverRef}
title="title"
content={AXIOM}
virtual-triggering
trigger="click"
/>
<div v-popover={popoverRef.value} id="reference-node">
trigger
</div>
</>
),
{
global: {
directives: {
[VPopover]: PopoverDirective,
},
},
}
)
}
describe('v-popover', () => {
afterEach(() => {
document.body.innerHTML = ''
})
it('should render correctly', async () => {
const wrapper = _mount()
await nextTick()
expect(document.body.querySelector('.el-popover')?.innerHTML).toContain(
AXIOM
)
wrapper.unmount()
})
it('should show popover when reference is mounted', async () => {
const wrapper = _mount()
await nextTick()
const refNode = '#reference-node'
expect(wrapper.find(refNode).exists()).toBe(true)
expect(
document.body.querySelector('.el-popover')?.getAttribute('style')
).toContain('display: none')
await wrapper.find(refNode).trigger('click', {
button: 0,
})
await nextTick()
await rAF()
expect(
document.body.querySelector('.el-popover')?.getAttribute('style')
).not.toContain('display: none')
wrapper.unmount()
})
})