Skip to content

Commit 5c4d1fc

Browse files
committed
test: add tests for -to- prop in tooltip-base
1 parent 417ac12 commit 5c4d1fc

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { mountSuspended } from '@nuxt/test-utils/runtime'
3+
import TooltipBase from '~/components/Tooltip/Base.vue'
4+
5+
describe('TooltipBase to prop', () => {
6+
it('teleports to body by default', async () => {
7+
await mountSuspended(TooltipBase, {
8+
props: {
9+
text: 'Tooltip text',
10+
isVisible: true,
11+
tooltipAttr: { 'aria-label': 'tooltip' },
12+
},
13+
slots: {
14+
default: '<button>Trigger</button>',
15+
},
16+
})
17+
18+
const tooltip = document.querySelector<HTMLElement>('[aria-label="tooltip"]')
19+
expect(tooltip).not.toBeNull()
20+
expect(tooltip?.textContent).toContain('Tooltip text')
21+
22+
const currentContainer = tooltip?.parentElement?.parentElement
23+
expect(currentContainer).toBe(document.body)
24+
})
25+
26+
it('teleports into provided container when using selector string', async () => {
27+
const container = document.createElement('div')
28+
container.id = 'tooltip-container'
29+
document.body.appendChild(container)
30+
31+
try {
32+
await mountSuspended(TooltipBase, {
33+
props: {
34+
text: 'Tooltip text',
35+
isVisible: true,
36+
to: '#tooltip-container',
37+
tooltipAttr: { 'aria-label': 'tooltip' },
38+
},
39+
slots: {
40+
default: '<button>Trigger</button>',
41+
},
42+
})
43+
44+
const tooltip = container.querySelector<HTMLElement>('[aria-label="tooltip"]')
45+
expect(tooltip).not.toBeNull()
46+
expect(tooltip?.textContent).toContain('Tooltip text')
47+
48+
const currentContainer = tooltip?.parentElement?.parentElement
49+
expect(currentContainer).toBe(container)
50+
} finally {
51+
container.remove()
52+
}
53+
})
54+
})

0 commit comments

Comments
 (0)