You can use Storybook tags to include, exclude, or skip specific stories during test execution.
1. Annotate Stories
Add tags to your component meta or individual stories. Tags must be defined inline as an array of strings due to Storybook's static analysis requirements (do not import constants for tags).
- Meta tags: Apply to all stories in a file.
- Story tags: Apply only to that specific story.
- Negation: Use
!tagname to remove a tag (e.g., tags: ['!test']).
2. Apply Filters
You can filter these tags in three ways:
- CLI Flags: Use
--includeTags, --excludeTags, or --skipTags. CLI flags take precedence over configuration file settings. - Config File: Define tags in your ejected
test-runner-jest.config.js.
Difference between Skip and Exclude:
--excludeTags: The story is completely ignored and does not appear in the output.--skipTags: The story is marked as "skipped" in the CLI output, which is useful for temporarily disabling tests.
const meta = {
component: Button,
tags: ['atom'],
};
export default meta;
// will inherit tags from project and meta to be ['dev', 'test', 'atom']
export const Primary = {};
export const Secondary = {
// will combine with project and meta tags to be ['dev', 'test', 'atom', 'design']
tags: ['design'],
};
export const Tertiary = {
// will combine with project and meta tags to be ['dev', 'atom']
tags: ['!test'],
};