/storybook-assistant:testing-suitefrom storybook-assistant
Sets up Storybook 10 testing with Vitest, Playwright, and axe-core: play-function interaction tests, a11y checks, and visual regression.
Ships in storybook-assistant. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Set up and configure comprehensive testing for Storybook 10 components, including interaction tests with play functions, accessibility testing with axe-core, and visual regression testing with Playwright.
This skill provides guidance on implementing modern component testing patterns using Storybook 10's integrated testing capabilities.
Configure the right testing setup based on:
Set up and write interaction tests using:
Configure accessibility validation with:
Set up visual regression tests with:
Stories with args and controls only (no automated tests).
Best for:
Setup:
export const Primary: Story = {
args: {
variant: 'primary',
children: 'Button',
},
};
Stories with play functions that test user interactions.
Best for:
Setup:
import { expect, userEvent, within } from 'storybook/test';
export const WithInteraction: Story = {
args: { children: 'Click me' },
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const button = canvas.getByRole('button');
await expect(button).toBeInTheDocument();
await userEvent.click(button);
await expect(button).toHaveFocus();
},
};
Stories with axe-core validation rules.
Best for:
Setup:
export const AccessibilityValidation: Story = {
args: { children: 'Button' },
parameters: {
a11y: {
config: {
rules: [
{ id: 'button-name', enabled: true },
{ id: 'color-contrast', enabled: true },
{ id: 'focus-visible', enabled: true },
],
},
},
},
};
Combination of interaction tests, accessibility tests, and visual regression.
Best for:
Storybook 10 uses Vitest as the default test runner:
Benefits:
Setup:
Add to package.json:
{
"scripts": {
"test-storybook": "test-storybook"
}
}
Run stories directly in unit tests (Vitest/Jest) - perfect for reusable component libraries.
Why use it:
Setup:
// Button.test.tsx
import { composeStories } from '@storybook/react';
import { render, screen } from '@testing-library/react';
import * as stories from './Button.stories';
// Convert all stories to testable components
const { Primary, Disabled, WithIcon } = composeStories(stories);
describe('Button', () => {
it('renders primary variant', () => {
render(<Primary />);
expect(screen.getByRole('button')).toHaveClass('btn-primary');
});
it('runs interaction test from story', async () => {
const { container } = render(<WithIcon />);
// Play function from story runs automatically
await WithIcon.play?.({ canvasElement: container });
expect(screen.getByRole('button')).toHaveFocus();
});
it('respects disabled state', () => {
render(<Disabled />);
expect(screen.getByRole('button')).toBeDisabled();
});
});
Single story:
import { composeStory } from '@storybook/react';
import meta, { Primary } from './Button.stories';
const PrimaryButton = composeStory(Primary, meta);
test('primary button', () => {
render(<PrimaryButton />);
// Test with all decorators and args applied
});
With custom args override:
const { Primary } = composeStories(stories);
test('custom label', () => {
render(<Primary>Custom Text</Primary>);
expect(screen.getByText('Custom Text')).toBeInTheDocument();
});
Real browser testing with Playwright:
Benefits:
Setup:
Storybook 10 includes Playwright by default. Configure in .storybook/test-runner-jest.config.js:
export default {
browsers: ['chromium', 'firefox', 'webkit'],
screenshot: 'only-on-failure',
video: 'retain-on-failure',
};
Query components using accessible selectors:
Recommended queries (in order of preference):
getByRole() - Semantic HTML rolesgetByLabelText() - Form labelsgetByPlaceholderText() - Input placeholdersgetByText() - Visible text contentgetByTestId() - Last resort onlyExample:
const button = canvas.getByRole('button', { name: /submit/i });
const input = canvas.getByLabelText('Email address');
const heading = canvas.getByRole('heading', { level: 1 });
export const ButtonInteraction: Story = {
args: {
onClick: fn(),
children: 'Click me',
},
play: async ({ args, canvasElement }) => {
const canvas = within(canvasElement);
const button = canvas.getByRole('button');
// Test rendering
await expect(button).toBeInTheDocument();
// Test click
await userEvent.click(button);
await expect(args.onClick).toHaveBeenCalledTimes(1);
// Test disabled state
await expect(button).not.toBeDisabled();
},
};
export const InputInteraction: Story = {
args: {
label: 'Username',
onChange: fn(),
},
play: async ({ args, canvasElement }) => {
const canvas = within(canvasElement);
const input = canvas.getByLabelText('Username');
// Test typing
await userEvent.type(input, 'john.doe');
await expect(input).toHaveValue('john.doe');
// Test change handler
await expect(args.onChange).toHaveBeenCalled();
// Test validation
await userEvent.clear(input);
await expect(input).toHaveValue('');
},
};
export const ModalInteraction: Story = {
args: {
isOpen: true,
onClose: fn(),
title: 'Confirm Action',
},
play: async ({ args, canvasElement }) => {
const canvas = within(canvasElement);
const dialog = canvas.getByRole('dialog');
// Test ARIA attributes
await expect(dialog).toHaveAttribute('aria-modal', 'true');
// Test focus trap
const firstButton = canvas.getAllByRole('button')[0];
firstButton.focus();
await expect(firstButton).toHaveFocus();
// Test ESC key
await userEvent.keyboard('{Escape}');
await expect(args.onClose).toHaveBeenCalled();
},
};
export const FormInteraction: Story = {
args: {
onSubmit: fn(),
},
play: async ({ args, canvasElement }) => {
const canvas = within(canvasElement);
// Fill form
await userEvent.type(canvas.getByLabelText('Email'), '[email protected]');
await userEvent.type(canvas.getByLabelText('Password'), 'password123');
// Submit
await userEvent.click(canvas.getByRole('button', { name: /submit/i }));
// Verify submission
await expect(args.onSubmit).toHaveBeenCalledWith({
email: '[email protected]',
password: 'password123',
});
},
};
export const WCAG_AA_Compliance: Story = {
parameters: {
a11y: {
config: {
rules: [
// Perceivable
{ id: 'color-contrast', enabled: true }, // 1.4.3
{ id: 'image-alt', enabled: true }, // 1.1.1
// Operable
{ id: 'button-name', enabled: true }, // 4.1.2
{ id: 'link-name', enabled: true }, // 4.1.2
{ id: 'focus-visible', enabled: true }, // 2.4.7
// Understandable
{ id: 'label', enabled: true }, // 3.3.2
{ id: 'valid-lang', enabled: true }, // 3.1.1
// Robust
{ id: 'aria-valid-attr', enabled: true }, // 4.1.2
{ id: 'aria-hidden-focus', enabled: true }, // 4.1.2
],
},
},
},
};
export const KeyboardNavigation: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// Tab through interactive elements
await userEvent.tab();
const firstButton = canvas.getAllByRole('button')[0];
await expect(firstButton).toHaveFocus();
// Activate with Enter
await userEvent.keyboard('{Enter}');
// Activate with Space
await userEvent.keyboard(' ');
// Navigate with arrows (for radio/tabs)
await userEvent.keyboard('{ArrowRight}');
},
};
# Run all tests
npm run test-storybook
# Run specific story
npm run test-storybook -- --stories "Button/WithInteraction"
# Watch mode
npm run test-storybook -- --watch
# Debug mode
npm run test-storybook -- --debug
Add to GitHub Actions:
name: Storybook Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- run: npm run build-storybook
- run: npm run test-storybook
Storybook 10 includes V8 coverage (faster than Istanbul):
{
"scripts": {
"test-storybook": "test-storybook --coverage",
"test-storybook:ci": "test-storybook --coverage --coverageReporters=lcov"
}
}
View coverage report:
npm run test-storybook -- --coverage
# Coverage report: coverage/lcov-report/index.html
getByRole() for semantic queriesgetByTestId() unless necessaryIncrease timeout in story:
export const SlowLoading: Story = {
parameters: {
test: {
timeout: 10000, // 10 seconds
},
},
};
Use findBy queries for async elements:
const button = await canvas.findByRole('button'); // Waits up to 1s
Add explicit waits:
await waitFor(() => {
expect(canvas.getByText('Loaded')).toBeInTheDocument();
});
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Generated from the plugin's indexed repository (flight505/storybook-assistant) — no native marketplace selected
npx claudepluginhub p/flight505-storybook-assistant18 skills in this plugin
/accessibility-remediationUse this skill when the user writes/edits components, asks to "fix accessibility issues", "add ARIA labels", "improve accessibility", "check WCAG compliance", "remediate a11y violations", mentions "screen reader support", "keyboard navigation", or wants AI-powered accessibility fixes with one-click application. Automatically analyzes components for a11y issues and suggests context-aware fixes. Trigger on PostToolUse hook or explicit request./ci-cd-generatorUse this skill when the user asks to "setup CI/CD", "configure GitHub Actions", "deploy Storybook", "setup Chromatic", "add visual regression to CI", "create deployment pipeline", or wants to generate complete CI/CD workflows for Storybook deployment and testing./component-scaffoldScaffold new components with stories, tests, and documentation following SOTA patterns and best practices/Component-Usage-AnalyticsComponent Usage AnalyticsUse this skill when users mention "component usage", "where is this component used", "deprecate component", "migration impact", "component analytics", or want to track and analyze component usage across the codebase with deprecation planning and migration impact analysis./dark-mode-generationUse this skill when the user asks to "generate dark mode", "create dark theme", "add dark mode support", "convert to dark mode colors", "generate dark color palette", or wants to automatically generate dark mode variants for their components with intelligent color inversion and accessibility preservation./design-to-codeUse this skill when the user uploads a design screenshot, shares a Figma export, provides a mockup image, or asks to "convert design to code", "build from mockup", "generate component from screenshot", "extract design to React", or wants to transform visual designs into production-ready components using Claude's vision capabilities.Other plugins' skills for the same job