Skip to content
Back to skills

Storybook Testing

ASecurity

Create Storybook stories with interaction tests for React components in CSF Next, using the .test() method. Covers visual states, clicks and typing, form validation UI and accessibility in isolation. Use when the user mentions Storybook, stories, CSF Next, .test() or wants to test a React component in isolation. NOT for pure functions or hooks (unit-testing), API endpoints (api-test) or full page flows (playwright-cli).

  • 2 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added October 13, 2026
developmenttypescriptgobashreacttestingapi

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 4 files and shows the line behind each finding

Scanned November 11, 2026

npx -y skills add JanSzewczyk/claude-plugins --skill storybook-testing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Storybook Testing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Storybook Testing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/janszewczyk-storybook-testing/badge)](https://www.skillsdirectory.com/skills/janszewczyk-storybook-testing)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: storybook-testing
description: Create Storybook stories with interaction tests for React components in CSF Next, using the .test() method. Covers visual states, clicks and typing, form validation UI and accessibility in isolation. Use when the user mentions Storybook, stories, CSF Next, .test() or wants to test a React component in isolation. NOT for pure functions or hooks (unit-testing), API endpoints (api-test) or full page flows (playwright-cli).
allowed-tools: Read, Write, Edit, Glob, Grep, Bash
---

# Storybook testing

Write stories with interaction tests for one React component. This file is the workflow. The rules
it applies are in the index below; each row links to the full rule with an incorrect and a correct
example.

## Workflow

1. **Read the component**: props, callbacks, conditional rendering, every state it can show, and
   anything it renders into a portal.
2. **Plan the stories**: one story per distinct state (different args mean a different story).
   Write the plan as a numbered comment at the top of the file.
3. **Get the data**: reuse a builder (`*.builder.ts`) for typed props; if none exists, run
   `/builder-factory` first.
4. **Write the file** next to the component as `<component>.stories.tsx`.
5. **Add the tests**: one `.test()` per independent behaviour, grouped as the rules below say.
6. **Run** `npm run test:storybook -- --grep "<Component>"`. Read each failure, fix, re-run.

## Rules

Open a rule's file when the step you are on touches it. `critical` rules apply to every file you
write.

<!-- BEGIN:knowledge -->
<!-- generated by knowledge.mjs from 11 note(s) (sha256 7d5fb987886c); edit the notes in knowledge/, then run build -->

| Impact | Rule | Applies to |
| --- | --- | --- |
| critical | [Take userEvent from the test function's parameters, never from an import](references/rules.md#take-userevent-from-the-test-functions-parameters-never-from-an-import) — An imported userEvent bypasses Storybook's instrumentation and breaks interaction timing. | typescript, storybook@>=10 |
| high | [Set every value the test asserts on explicitly when you build test data](references/rules.md#set-every-value-the-test-asserts-on-explicitly-when-you-build-test-data) — Let the builder randomise what the test ignores; pass an override for every value the test checks. | any |
| high | [Find elements the way a user or a screen reader does](references/rules.md#find-elements-the-way-a-user-or-a-screen-reader-does) — Query by role and accessible name, then label, then visible text; never by test id, CSS selector or internals. | any |
| high | [Query portal content through screen, not canvas](references/rules.md#query-portal-content-through-screen-not-canvas) — Dialogs, popovers, tooltips and option lists render into document.body, outside the story root that canvas sees. | typescript, storybook@>=10 |
| high | [Attach independent checks to one story with .test(), not separate play stories](references/rules.md#attach-independent-checks-to-one-story-with-test-not-separate-play-stories) — One .test() per independent behaviour; play only for a demo or one flow whose steps depend on each other. | typescript, storybook@>=10 |
| high | [Write stories with CSF Next factories, not CSF 3 objects](references/rules.md#write-stories-with-csf-next-factories-not-csf-3-objects) — preview.meta() and meta.story() give inferred types and the .test() method; CSF 3 objects give neither. | storybook@>=10 |
| high | [Put a React story next to its component and import the typed preview](references/rules.md#put-a-react-story-next-to-its-component-and-import-the-typed-preview) — component.stories.tsx beside the component, import preview from "~/.storybook/preview", no default export. | typescript, react, storybook@>=10 |
| high | [Pick getBy, queryBy or findBy by what the assertion expects](references/rules.md#pick-getby-queryby-or-findby-by-what-the-assertion-expects) — getBy* for elements that must be there, queryBy* to assert absence, findBy* for anything that appears later. | typescript, testing-library |
| medium | [Reset builder counters and random state between tests that depend on them](references/rules.md#reset-builder-counters-and-random-state-between-tests-that-depend-on-them) — Sequences and seeded randomness carry over between tests; reset them where a test depends on their values. | any |
| medium | [Group assertions by category, not one test per element](references/rules.md#group-assertions-by-category-not-one-test-per-element) — One content test per state, one accessibility test, one test per distinct interaction, rule or callback. | typescript, storybook@>=10 |
| low | [Name stories after component states and tests after behaviours](references/rules.md#name-stories-after-component-states-and-tests-after-behaviours) — Stories are states (EmptyForm, LoadingButton), tests are sentences; never Default, Basic or Test 1. | typescript, storybook@>=10 |

<!-- END:knowledge -->

## Before you write

- Which interactions, validation rules and keyboard paths must be covered?
- Which states exist (loading, error, empty, success), and which need their own story?
- What needs mocking: callbacks (`fn()`), network (MSW), modules (`sb.mock()`), context
  (decorators), data (builders)?
- Does anything render in a portal?

Files in this skill

  • SKILL.md15 KB
  • references/api-reference.md11.4 KB
  • references/examples.md20.1 KB
  • references/mocking.md18.8 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.