shadcn/ui Component Testing
БесплатноБез исполняемых скриптовНе проверенTesting skill for shadcn/ui and Radix UI component libraries covering accessible component testing, dialog and popover testing, form validation testing, data…
от PramodDutta★ 253 звезды на GitHubОб этом скилле
shadcn/ui Component Testing Skill
You are an expert software engineer specializing in testing shadcn/ui and Radix UI component libraries. When the user asks you to write, review, or debug tests for shadcn/ui components including Dialog, Popover, Form, DataTable, Command palette, and theme switching, follow these detailed instructions.
Core Principles
- Test user interactions, not Radix internals -- Radix primitives are well-tested; focus on your composition and customization.
- Use accessible queries -- Prefer
getByRole,getByLabelText, andgetByTextover CSS selectors to ensure ARIA compliance. - Test keyboard navigation -- shadcn/ui components support full keyboard interaction; verify tab order, arrow keys, and escape.
- Verify portal rendering -- Dialogs, popovers, and dropdowns render in portals; use
screenqueries, not container queries. - Test form integration -- shadcn/ui forms use react-hook-form + zod; test validation messages and submission behavior.
- Assert on visual states -- Test open/closed, disabled, loading, and error states explicitly.
- Test theme switching -- Verify components render correctly in both light and dark modes.
Project Structure
project/
src/
components/
ui/
button.tsx
dialog.tsx
popover.tsx
select.tsx
form.tsx
data-table.tsx
command.tsx
sheet.tsx
accordion.tsx
toast.tsx
__tests__/
button.test.tsx
dialog.test.tsx
popover.test.tsx
select.test.tsx
form.test.tsx
data-table.test.tsx
command.test.tsx
sheet.test.tsx
accordion.test.tsx
toast.test.tsx
theme-switching.test.tsx
keyboard-navigation.test.tsx
test-utils/
render-with-providers.tsx
mock-data.ts
accessibility-helpers.ts
vitest.config.ts
playwright.config.ts
Test Utilities Setup
// src/components/test-utils/render-with-providers.tsx
import React, { ReactElement } from 'react';
import { render, RenderOptions } from '@testing-library/react';
import { ThemeProvider } from 'next-themes';
import { Toaster } from '@/components/ui/toaster';
interface TestProviderOptions {
theme?: 'light' | 'dark' | 'system';
}
function TestProviders({
children,
theme = 'light',
}: {
children: React.ReactNode;
theme?: string;
}) {
return (
<ThemeProvider attribute="class" defaultTheme={theme} enableSystem={false}>
{children}
<Toaster />
</ThemeProvider>
);
}
export function renderWithProviders(
ui: ReactElement,
options?: RenderOptions & TestProviderOptions
) {
const { theme, ...renderOptions } = options || {};
return render(ui, {
wrapper: ({ children }) => (
<TestProviders theme={theme}>{children}</TestProviders>
),
...renderOptions,
});
}
export * from '@testing-library/react';
export { renderWithProviders as render };
// src/components/test-utils/accessibility-helpers.ts
import { axe, toHaveNoViolations } from 'jest-axe';
expect.extend(toHaveNoViolations);
export async function expectNoA11yViolations(container: HTMLElement) {
const results = await axe(container);
expect(results).toHaveNoViolations();
}
export function expectFocusVisible(element: HTMLElement) {
expect(element).toHaveFocus();
expect(document.activeElement).toBe(element);
}
export function expectAriaExpanded(element: HTMLElement, expanded: boolean) {
expect(element).toHaveAttribute('aria-expanded', String(expanded));
}
export function expectAriaSelected(element: HTMLElement, selected: boolean) {
expect(element).toHaveAttribute('aria-selected', String(selected));
}
Dialog Testing
// src/components/__tests__/dialog.test.tsx
import { describe, it, expect, vi } from 'vitest';
import { render, screen, waitFor } from '../test-utils/render-with-providers';
import userEvent from '@testing-library/user-event';
import {
Dialog,
DialogTrigger,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
DialogFooter,
DialogClose,
} from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { expectNoA11yViolations } from '../test-utils/accessibility-helpers';
function ConfirmDialog({
onConfirm,
onCancel,
}: {
onConfirm: () => void;
onCancel?: () => void;
}) {
return (
<Dialog>
<DialogTrigger asChild>
<Button>Delete Item</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Are you sure?</DialogTitle>
<DialogDescription>
This action cannot be undone. This will permanently delete the item.
</DialogDescription>
</DialogHeader>
<DialogFooter>
<DialogClose asChild>
<Button variant="outline" onClick={onCancel}>
Cancel
</Button>
</DialogClose>
Установить shadcn/ui Component Testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл shadcn/ui Component Testing?
Testing skill for shadcn/ui and Radix UI component libraries covering accessible component testing, dialog and popover testing, form validation testing, data table testing, command palette testing, and theme switching verification.
Как установить скилл shadcn/ui Component Testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл shadcn/ui Component Testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic