Files
nuxt__ui/test/components/Tooltip.spec.ts
Jakub Michálek f2d73e5bee test(components): add a11y tests (#5181)
Co-authored-by: Jakub <jakub.michalek@freelo.io>
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
2025-10-14 13:56:06 +02:00

54 lines
1.8 KiB
TypeScript

import { defineComponent } from 'vue'
import { describe, it, expect } from 'vitest'
import { axe } from 'vitest-axe'
import { mountSuspended } from '@nuxt/test-utils/runtime'
import { TooltipProvider } from 'reka-ui'
import Tooltip from '../../src/runtime/components/Tooltip.vue'
import type { TooltipProps, TooltipSlots } from '../../src/runtime/components/Tooltip.vue'
import ComponentRender from '../component-render'
const TooltipWrapper = defineComponent({
components: {
TooltipProvider,
UTooltip: Tooltip
},
inheritAttrs: false,
template: `<TooltipProvider>
<UTooltip v-bind="$attrs">
<template v-for="(_, name) in $slots" #[name]="slotData">
<slot :name="name" v-bind="slotData" />
</template>
</UTooltip>
</TooltipProvider>`
})
describe('Tooltip', () => {
const props = { text: 'Tooltip', open: true, portal: false }
it.each([
// Props
['with text', { props }],
['with arrow', { props: { ...props, arrow: true } }],
['with kbds', { props: { ...props, kbds: ['meta', 'K'] } }],
['with class', { props: { ...props, class: 'text-sm' } }],
['with ui', { props: { ...props, ui: { content: 'text-sm' } } }],
// Slots
['with default slot', { props, slots: { default: () => 'Default slot' } }],
['with content slot', { props, slots: { content: () => 'Content slot' } }]
])('renders %s correctly', async (nameOrHtml: string, options: { props?: TooltipProps, slots?: Partial<TooltipSlots> }) => {
const html = await ComponentRender(nameOrHtml, options, TooltipWrapper)
expect(html).toMatchSnapshot()
})
it('passes accessibility tests', async () => {
const wrapper = await mountSuspended(TooltipWrapper, {
props: {
...props,
arrow: true,
kbds: ['meta', 'K']
}
})
expect(await axe(wrapper.element)).toHaveNoViolations()
})
})