forked from
npmx.dev/npmx.dev
[READ-ONLY]
a fast, modern browser for the npm registry
1import { describe, expect, it } from 'vitest'
2import { mountSuspended } from '@nuxt/test-utils/runtime'
3import TooltipBase from '~/components/Tooltip/Base.vue'
4
5describe('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})