1---2name: react-testable-storybookable3description: >-4 Scaffolds React components that are jointly unit-testable and Storybook-ready5 with MSW and clear seams. Use this skill when creating new components that6 need tests and stories from day one. Do not use when/for end-to-end browser7 automation (use agent-browser) or journey-level Storybook docs without8 scaffolding (use storybook-journeys).9version: 1.1.010libraries: ["@tanstack/react-query", "msw", "@storybook/test", "@testing-library/react", "vitest"]11---1213# React Testable & Storybookable1415## Critical rules1617- A component may depend on **props** and **injectable context** only — never network, router, or an unoverridable global store.18- Testability and storybookability are the same property: shared fixtures, shared MSW, shared providers.19- Leaf/presentational stays props-only; push fetching into a thin container.20- Hooks surface explicit `idle` / `loading` / `success` / `error`; React Query uses a key factory.21- One MSW handler/fixture set backs Vitest, Storybook, and optional local mocks.22- Ship the trio: `Component.tsx` + `Component.stories.tsx` + `Component.test.tsx`.23- Export props types; type stories from them. `QueryClient` in tests has `retry: false`.24- Before scaffolding harness files or WRONG/CORRECT samples, read the matching resource below.2526## Workflow27281. Classify tier: leaf (props), container (hooks + providers), or provider/boundary.292. Keep API/router out of the leaf; pass data and callbacks as props.303. Before writing harness or MSW boilerplate, read [references/scaffold.md](references/scaffold.md).314. Add `renderWithProviders` (theme, router, QueryClient with retries off) and shared fixtures/handlers with failure injection + store reset.325. For containers that read context, add a test-only provider implementing the same `state` / `actions` / `meta` contract.336. Scaffold the file trio: `scripts/scaffold-component.sh <ComponentName> [target-dir]` (see `--help`).347. Stories: Default, Empty, Loading, Error; handlers via `fn()`. Import shared fixtures.358. Wire Storybook `preview` with MSW + providers + a11y addon.369. For WRONG/CORRECT prop, hook, and story patterns, read [references/examples.md](references/examples.md).3738## Resources3940- [references/examples.md](references/examples.md) — prop-driven, keys/hooks, MSW, trio, test provider. Read when implementing.41- [references/scaffold.md](references/scaffold.md) — copy-paste harness: utils, MSW, providers, decorators. Read when setting up a project.42- [scripts/scaffold-component.sh](scripts/scaffold-component.sh) — generates the component/stories/test trio. Run with `--help` for usage; refuse overwrite.4344## Validation4546- [ ] Leaf depends only on props + injectable context47- [ ] Explicit status / key factory for hooks48- [ ] Trio present; stories cover Default, Empty, Loading, Error with `fn()`49- [ ] Stories and tests share fixtures; containers use `renderWithProviders` + MSW50- [ ] `QueryClient` retry off; store reset between tests51- [ ] Storybook preview wires MSW + providers + a11y5253## Constraints5455- Page-level flows belong in `storybook-journeys`. Visual tokens in `ui-design-principles`. Architecture baseline in `react-development`.56- Adjacent: `result-types`, `testing-strategy`, `validation-boundary`. Prefer composition patterns over boolean-prop sprawl.