No slash command · from svelte-5
Wires Svelte CSF stories as Vitest browser tests via @storybook/addon-vitest: play functions, tags, decorators, asChild. Debugs CI failures, 'Vitest failed to find the current suite', and props_invalid_value errors.
Ships in svelte-5. 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.
Read when SKILL.md points to them.
Stories are .stories.svelte with defineMeta and <Story> from @storybook/addon-svelte-csf; ignore JSX/TSX/CSF3-TS story patterns here. Official reference: Vitest addon, use it for plugin, browser mode, CLI, tags, debugging, CI; ignore non-Svelte story file examples there. Manual setup · Example configuration files · Options
storybookTest turns stories into Vitest tests via portable stories (Vitest). No Storybook server required for the test run<Story>: smoke render; a play function runs as the interaction test (interaction testing, asserting with expect)play assertion fails on what did not render. Vitest reports that throw as an "unhandled error", exits non-zero, and names "the last test to run before this error". Find the throwing component in that block's ❯ source frames: its component stack can show it as in <unknown>. Exception: when a decorator returns a bare component (() => Wrapper), the Vitest run renders the defineMeta component without props in its place, and a throw from that instance fails its story and prints under that failed story (references/storybook-decorator.md, "Decorator return form"). A console.error alone does not fail anything. Read the "Unhandled Errors" block, not just the pass count--silent hides the console output of every story. Separately, an AI agent's run with no reporter set in the config or the CLI uses Vitest's minimal reporter, which hides the output of passing stories even without --silent. --silent=false shows it (references/config.md)play misses errors logged during render):
let errorSpy; in <script module> (let errorSpy: ReturnType<typeof spyOn>; in lang="ts")defineMeta: beforeEach: () => { errorSpy = spyOn(console, 'error'); return () => errorSpy.mockRestore() } (spyOn from storybook/test)play: await expect(errorSpy).not.toHaveBeenCalled(), which fails on an error logged at mountvitest --coverage --project … only covers projects you pass (SETUP.md's test:unit omits storybook; test:storybook runs it).stories.svelte + playUse storybook/test (expect, within, userEvent, waitFor) in play. Scope queries with canvasElement to within(canvasElement).
Every story with interactive elements (inputs, autocompletes,
buttons, forms) MUST have a play function that interacts and
asserts the result. A smoke render (<Story name="Default" />)
stays green even when a component inside the story throws while rendering, or the story
renders nothing. In play:
if (items.length > 1)
guards; if the dropdown should have options, assert that it has themA play function that opens a dropdown but never selects a value is
not a test, and neither is one that selects a value but never checks
WHICH value. Assert the value the interaction produced, for example
the exact string an autocomplete's onChange received: checking only
that something was selected misses a callback that passes objects
instead of strings.
Tags: default storybookTest({ tags: { include: ['test'], … } }) (API), only stories carrying an included tag run; test is applied to every story by default, so a story stays out of the run only through !test, a tag in exclude, a tag in skip, or a custom include list. !test, exclude, and a non-matching include drop the story before Vitest sees it: it is neither run nor counted. A tag in skip keeps the story as a skipped test (1 passed | 1 skipped in the test count). Add other tags to include only to pick up stories that opted out with !test (a story tagged only autodocs already runs, because it also carries the default test tag). Set tags on defineMeta / stories or adjust include / exclude / skip (exclude wins if the same tag is both included and excluded).
<script module>
import { defineMeta } from "@storybook/addon-svelte-csf";
import { expect, within, userEvent } from "storybook/test";
import MyComponent from "./MyComponent.svelte";
const { Story } = defineMeta({
title: "MyComponent",
component: MyComponent,
});
</script>
<Story
name="Default"
play={async ({ canvasElement }) => {
const canvas = within(canvasElement);
const button = canvas.getByRole("button");
await userEvent.click(button);
// getByText matches the full text by default: this checks the text the click produced
await expect(canvas.getByText("Clicked")).toBeVisible();
}}
/>
A !test story next to a running story in the same file leaves Tests 1 passed (1). A file in which no story survives the filter counts as one skipped test file (Test Files 1 skipped (1), Tests no tests), not as skipped stories: the transformer replaces it with a placeholder describe.skip (transformer source). The skipped count therefore does not tell you which stories never ran: search for !test and for every tag listed in exclude or skip, not for stories without tags.
Two expects, two semantics. expect from storybook/test (used in play) is Chai + jest-dom: its toHaveTextContent('Cli') passes on Click and accepts a RegExp. Vitest 5's browser expect.element(...).toHaveTextContent is an exact full-string match. Do not copy assertions between story play functions and Vitest browser tests without checking which expect they use. toMatchScreenshot exists only on Vitest's expect: in play, import expect from vitest and page from vitest/browser, then wrap the canvas with page.elementLocator(canvasElement) (svelte-5:vitest visual-regression reference).
Test name in output: use name on <Story> (custom name FAQ).
Vitest failed to find the current suite: an optimizeDeps reload mid-test, shown by:
dependency optimized: or dependencies optimized:, then optimized dependencies changed. reloading✨ new dependencies optimized:, then ✨ optimized dependencies changed. reloadingVite unexpectedly reloaded a testFix:
Failed to run dependency scan. Skipping dependency pre-bundling., Vite skipped the scan; dependencies outside optimizeDeps.include may then be found while tests run. Read the error printed with it and fix its cause; when it points into a dependency, report it to that package (svelte-5:vitest flake-hygiene reference)dependency optimized: or dependencies optimized: line; earlier Vite releases: the ✨ new dependencies optimized: line) to optimizeDeps.include (FAQ) on the storybook project config itself, copying each specifier verbatim from your own import statements. Common culprits: msw-storybook-addon/preview on the addon's createPreviewAnnotations path (the storybook project pre-bundles msw-storybook-addon/csf3 itself: svelte-5:msw), @storybook/addon-svelte-csf, @storybook/addon-docs. To let the scan find deps itself, list its start files in optimizeDeps.entries (svelte-5:vitest flake-hygiene reference, Settings)... is not exported under the conditions [...], Test Files no tests); a package that is not installed only warns (Failed to resolve dependency) and the run passes; an entry that resolves but is not what you import passes silently and pre-bundles the wrong module. Only the first is loudSingle-run bias: this addon is PARTICULARLY prone to different test counts between runs on the same checkout. A "Test Files N passed (N)" line on one run does NOT prove the suite is healthy: NEVER claim "fixed" or "green" from a single run on this suite. If the user shows a failing screenshot and your run goes green, first acknowledge you cannot reproduce their failure and ask for their log or reproduction conditions, rather than re-running for another green. See frontend:validate flake rules and the svelte-5:vitest flake-hygiene reference
Do not enshrine unverified approaches as "better fixes" in this skill. A new approach to a storybook/vitest problem goes through the full flake-hygiene protocol on a real failure before it is written down as a recommendation; unverified does not go in the skill
ALWAYS run the storybook project with --silent (the SETUP.md scripts test:storybook and test:story pass it): otherwise story and msw console output buries the errors. To see the console output of one story file, run pnpm exec vitest run --project storybook --silent=false <file> (storybook being your storybook project's name), not pnpm test:story, which always passes --silent. Which reporter shows what: references/config.md
More FAQ items (Interactions panel vs CLI, Vitest internal errors, publicDir, CI isolation and sharding, WebGL launch args, isolating test from vite.config): references/config.md
asChild, decorators, and context() => ({ Component: Wrapper }). A bare () => Wrapper works in the Storybook UI but not in the Vitest run, where an argless instance of the defineMeta component (if it has one) renders in its place, with no render error unless that component throws without props (references/storybook-decorator.md, "Decorator return form")setContext provides that context to the story component, in the Vitest run and in the Storybook UI: with Svelte CSF, DecoratorHandler renders the CSF story renderer inside the decorator, and the story component inside thatasChild and a decorator in that form can share a story: the asChild content renders inside the story renderer, so the component renders once, with the props you passasChild when the story passes props to the component inline rather than through args, or renders a wrapper component around it (references/storybook-decorator.md, "asChild pattern"; svelte-5:storybook)svelte-5:vitest skillsvelte-5:testing-svelte skillmsw in .storybook/preview, handlers, story-scoped mocks, and the msw and msw-storybook-addon 2 to 3 migration: svelte-5:msw skillreferences/storybook-decorator.md: read when a story throws props_invalid_value or renders empty, when a decorator's markup, context or store values work in the Storybook UI but are missing in the Vitest run, when a story fails only in the Vitest run with its defineMeta component throwing as if it had no props, and for the asChild wrapper patternreferences/config.md: read when setting up @storybook/addon-vitest, or creating or changing vitest.config, the storybook project, test scripts, --silent or plugin optionsWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
storybook, vitest, svelte-csf, interaction-testing, browser-testing
npx claudepluginhub fubits1/svelte-skills --plugin svelte-58 skills in this plugin
/code-style-svelteSvelte component code style rules. Auto-invoke when creating .svelte files, editing component structure, transitions or layout reads, or SvelteKit URL state and navigation guards. Covers component docs and Svelte style conventions./composition-svelteUse when composing a Svelte 5 feature from provider/wrapper components, content snippets, reactive state, or third-party DOM bridging (maplibre, leaflet, d3, tippy, popper). Covers overlay wrappers, snippet APIs, and state location./doc-componentDocument a Svelte component using @component JSDoc. Auto-invoke when asked to document a .svelte component. Reads the component, analyzes its interface, and writes a structured @component comment block./mswMocks HTTP with msw 3 in Svelte, Storybook, Vitest and SvelteKit. Use when writing http.get handlers or parameters.msw, upgrading from msw 2, or debugging blank stories, handler order, query strings, onUnhandledFrame or mockServiceWorker.js./storybookStorybook authoring and browser checks for Svelte: MCP instructions, previews, Svelte 4 store wrappers, CSS imports in preview.ts. Use when writing or reviewing .stories.svelte files, moving a CSS import that stories need, or a story renders empty./testing-svelteFix or write Svelte 5 tests with vitest-browser-svelte and Playwright. Use when debugging broken or flaky tests, 'Cannot connect to the iframe', strict mode violations, or writing unit/SSR/e2e tests.Other plugins' skills for the same job