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

36 lines
1.4 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { axe } from 'vitest-axe'
import { mountSuspended } from '@nuxt/test-utils/runtime'
import Page from '../../src/runtime/components/Page.vue'
import type { PageProps, PageSlots } from '../../src/runtime/components/Page.vue'
import ComponentRender from '../component-render'
describe('Page', () => {
it.each([
// Props
['with as', { props: { as: 'section' } }],
['with class', { props: { class: 'lg:gap-4' } }],
['with ui', { props: { ui: { right: 'order-last lg:order-first' } } }],
// Slots
['with default slot', { slots: { default: () => 'Default slot' as any } }],
['with left slot', { slots: { left: () => 'Left slot' as any } }],
['with right slot', { slots: { right: () => 'Right slot' as any } }],
['with all slots', { slots: { left: () => 'Left slot' as any, right: () => 'Right slot' as any, default: () => 'Default slot' as any } }]
])('renders %s correctly', async (nameOrHtml: string, options: { props?: PageProps, slots?: Partial<PageSlots> }) => {
const html = await ComponentRender(nameOrHtml, options, Page)
expect(html).toMatchSnapshot()
})
it('passes accessibility tests', async () => {
const wrapper = await mountSuspended(Page, {
slots: {
default: () => 'Default slot',
left: () => 'Left slot',
right: () => 'Right slot'
}
})
expect(await axe(wrapper.element)).toHaveNoViolations()
})
})