Files
nuxt__ui/test/components/Avatar.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

43 lines
1.8 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { axe } from 'vitest-axe'
import { mountSuspended } from '@nuxt/test-utils/runtime'
import Avatar from '../../src/runtime/components/Avatar.vue'
import type { AvatarProps, AvatarSlots } from '../../src/runtime/components/Avatar.vue'
import ComponentRender from '../component-render'
import theme from '#build/ui/avatar'
describe('Avatar', () => {
const sizes = Object.keys(theme.variants.size) as any
it.each([
// Props
['with src', { props: { src: 'https://github.com/benjamincanac.png' } }],
['with alt', { props: { alt: 'Benjamin Canac' } }],
['with text', { props: { text: '+1' } }],
['with icon', { props: { icon: 'i-lucide-image' } }],
['with chip', { props: { chip: { text: '1' } } }],
...sizes.map((size: string) => [`with size ${size}`, { props: { src: 'https://github.com/benjamincanac.png', size } }]),
['with as', { props: { as: 'section' } }],
['with as (object)', { props: { src: 'https://github.com/benjamincanac.png', as: { root: 'section', img: 'p' } } }],
['with as (partial object)', { props: { src: 'https://github.com/benjamincanac.png', as: { img: 'p' } } }],
['with class', { props: { class: 'bg-default' } }],
['with ui', { props: { ui: { fallback: 'font-bold' } } }],
// Slots
['with default slot', { slots: { default: '🇫🇷' } }]
])('renders %s correctly', async (nameOrHtml: string, options: { props?: AvatarProps, slots?: AvatarSlots }) => {
const html = await ComponentRender(nameOrHtml, options, Avatar)
expect(html).toMatchSnapshot()
})
it('passes accessibility tests', async () => {
const wrapper = await mountSuspended(Avatar, {
props: {
alt: 'Benjamin Canac',
src: 'https://github.com/benjamincanac.png'
}
})
expect(await axe(wrapper.element)).toHaveNoViolations()
})
})