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

49 lines
1.5 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { axe } from 'vitest-axe'
import { mountSuspended } from '@nuxt/test-utils/runtime'
import BlogPosts from '../../src/runtime/components/BlogPosts.vue'
import type { BlogPostsProps, BlogPostsSlots } from '../../src/runtime/components/BlogPosts.vue'
import ComponentRender from '../component-render'
describe('BlogPosts', () => {
const posts = [{
title: 'Title',
description: 'Description',
date: '2024-12-13T09:32:32.598Z',
image: {
src: 'https://picsum.photos/640/360',
alt: 'Image alt'
},
badge: { label: 'Badge' },
authors: [{
name: 'Author',
avatar: {
src: 'https://i.pravatar.cc/120?img=1'
}
}]
}]
const props = { posts }
it.each([
// Props
['with posts', { props }],
['with orientation vertical', { props: { ...props, orientation: 'vertical' as const } }],
['with as', { props: { ...props, as: 'section' } }],
['with class', { props: { ...props, class: 'gap-y-12' } }],
// Slots
['with default slot', { props, slots: { default: () => 'Default slot' } }]
])('renders %s correctly', async (nameOrHtml: string, options: { props?: BlogPostsProps, slots?: Partial<BlogPostsSlots> }) => {
const html = await ComponentRender(nameOrHtml, options, BlogPosts)
expect(html).toMatchSnapshot()
})
it('passes accessibility tests', async () => {
const wrapper = await mountSuspended(BlogPosts, {
props
})
expect(await axe(wrapper.element)).toHaveNoViolations()
})
})