Loading...
Loading...
Scaffolds comprehensive testing setup for Next.js applications including Vitest unit tests, React Testing Library component tests, and Playwright E2E flows with accessibility testing via axe-core. This skill should be used when setting up test infrastructure, generating test files, creating test utilities, adding accessibility checks, or configuring testing frameworks for Next.js projects. Trigger terms include setup testing, scaffold tests, vitest, RTL, playwright, e2e tests, component tests, unit tests, accessibility testing, a11y tests, axe-core, test configuration.
npx skill4agent add hopeoverture/worldbuilding-app-skills testing-next-stackscripts/generate_test_deps.pypython scripts/generate_test_deps.py --nextjs-version <version> --typescriptvitest@testing-library/react@testing-library/jest-dom@testing-library/user-event@playwright/test@axe-core/playwright@vitejs/plugin-reactjsdomassets/vitest.config.tsassets/vitest.config.tsplaywright.config.tsassets/playwright.config.tstest/setup.tsassets/test-setup.tstest/utils/test/utils/render.tsxtest/utils/factories.tstest/utils/helpers.tstest/unit/example.test.tsassets/examples/unit-test.tstest/component/example.test.tsxassets/examples/component-test.tsxtest/e2e/example.spec.tsassets/examples/e2e-test.ts{
"scripts": {
"test": "vitest",
"test:ui": "vitest --ui",
"test:coverage": "vitest --coverage",
"test:e2e": "playwright test",
"test:e2e:ui": "playwright test --ui",
"test:e2e:debug": "playwright test --debug"
}
}import { describe, it, expect } from 'vitest'
import { validateEntityRelationship } from '@/lib/validation'
describe('validateEntityRelationship', () => {
it('validates valid relationship', () => {
const result = validateEntityRelationship({
sourceId: '1',
targetId: '2',
type: 'BELONGS_TO'
})
expect(result.isValid).toBe(true)
})
it('rejects self-referential relationship', () => {
const result = validateEntityRelationship({
sourceId: '1',
targetId: '1',
type: 'BELONGS_TO'
})
expect(result.isValid).toBe(false)
})
})import { render, screen } from '@/test/utils/render'
import { userEvent } from '@testing-library/user-event'
import { axe } from '@axe-core/playwright'
import EntityCard from '@/components/EntityCard'
describe('EntityCard', () => {
it('renders entity information', () => {
render(<EntityCard entity={mockEntity} />)
expect(screen.getByText(mockEntity.name)).toBeInTheDocument()
})
it('handles edit action', async () => {
const onEdit = vi.fn()
render(<EntityCard entity={mockEntity} onEdit={onEdit} />)
await userEvent.click(screen.getByRole('button', { name: /edit/i }))
expect(onEdit).toHaveBeenCalledWith(mockEntity.id)
})
it('has no accessibility violations', async () => {
const { container } = render(<EntityCard entity={mockEntity} />)
const results = await axe(container)
expect(results.violations).toHaveLength(0)
})
})import { test, expect } from '@playwright/test'
import { injectAxe, checkA11y } from '@axe-core/playwright'
test('user creates new entity', async ({ page }) => {
await page.goto('/entities')
// Inject axe for accessibility testing
await injectAxe(page)
// Navigate to create form
await page.getByRole('button', { name: /create entity/i }).click()
// Fill form
await page.getByLabel(/name/i).fill('New Character')
await page.getByLabel(/type/i).selectOption('character')
await page.getByLabel(/description/i).fill('A mysterious traveler')
// Submit
await page.getByRole('button', { name: /save/i }).click()
// Verify success
await expect(page.getByText('New Character')).toBeVisible()
// Check accessibility
await checkA11y(page)
})import { render } from '@/test/utils/render'
import { axe, toHaveNoViolations } from 'jest-axe'
expect.extend(toHaveNoViolations)
it('meets accessibility standards', async () => {
const { container } = render(<MyComponent />)
const results = await axe(container)
expect(results).toHaveNoViolations()
})import { test } from '@playwright/test'
import { injectAxe, checkA11y, getViolations } from '@axe-core/playwright'
test('homepage accessibility', async ({ page }) => {
await page.goto('/')
await injectAxe(page)
// Check entire page
await checkA11y(page)
// Or check specific element
await checkA11y(page, '#main-content')
// Or get violations for custom reporting
const violations = await getViolations(page)
expect(violations).toHaveLength(0)
})vitest.config.tsexport default defineConfig({
test: {
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
exclude: [
'node_modules/',
'test/',
'**/*.config.{ts,js}',
'**/*.d.ts'
],
thresholds: {
lines: 80,
functions: 80,
branches: 80,
statements: 80
}
}
}
})references/vitest-setup.mdreferences/rtl-patterns.mdreferences/playwright-setup.mdreferences/a11y-testing.mdassets/vitest.config.tsassets/playwright.config.tsassets/test-setup.tsassets/examples/npm installnpm testnpm run test:e2e