
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@chanzuckerberg/axe-storybook-testing
Advanced tools
[](https://www.npmjs.com/package/@chanzuckerberg/axe-storybook-testing) 
Command line interface for running accessibility tests (using axe-core) on your Storybook stories.
If there are any violations, information about them will be printed, and the command will exit with a non-zero exit code. That way, you can use this as automated accessibility tests on CI.
# via npm
npm install --save-dev @chanzuckerberg/axe-storybook-testing
# or, if using Yarn
yarn add --dev @chanzuckerberg/axe-storybook-testing
This package works by analyzing the static files that Storybook produces. Therefore, Storybook's build command must be ran first.
To make this as easy as possible to use, we recommend adding a script to your package.json that builds Storybook and then executes the axe-storybook command.
// In package.json
"scripts": {
"storybook:axe": "build-storybook && axe-storybook"
},
Then you can run the tests with
# If using npm
npm run storybook:axe
# or, if using Yarn
yarn storybook:axe
The command-line interface has the following options.
| Option | Default | Type | Description |
|---|---|---|---|
--browser | chromium | chromium, firefox, or webkit | Which browser to run the tests in |
--build-dir | storybook-static | string | Storybook static build directory |
--storybook-address | string | Storybook server address to test against instead of using a static build directory. If set, --build-dir will be ignored. e.g. --storybook-address http://localhost:6006 | |
--failing-impact | all | minor, moderate, serious, critical, or all | The lowest impact level that should be considered a failure |
--format | spec | string | Format to output test data in. Right now the only option is "spec" |
--headless | true | boolean | Whether to run headlessly or not |
--pattern | .* | string regex | Only run tests that match a component name pattern |
--timeout | 2000 | number | Timeout (in milliseconds) for each test |
For example, to run non-headlessly on Firefox, you would run
# If using npm
npm run storybook:axe -- --headless false --browser firefox
# or, if using Yarn
yarn storybook:axe --headless false --browser firefox
Stories can use parameters to configure how axe-storybook-testing handles them.
Prevent axe-storybook-testing from running a story by using the skip parameter.
// SomeComponent.stories.jsx
SomeStory.parameters = {
axe: {
skip: true,
},
};
Prevent axe-storybook-testing from running specific Axe rules on a story by using the disabledRules parameter.
// SomeComponent.stories.jsx
SomeStory.parameters = {
axe: {
disabledRules: ['select-name'],
},
};
Rules can also be disabled globally by setting this parameter for all stories in .storybook/preview.js.
// .storybook/preview.js
export const parameters = {
axe: {
disabledRules: ['select-name'],
},
};
Wait for an arbitrary CSS selector after rendering before running the Axe checks. Useful if your component takes some time to render and actually display itself on the page.
// SomeComponent.stories.jsx
export const parameters = {
axe: {
waitForSelector: '#some-component-selector',
},
};
If you want to work on this project or contribute back to it, see our wiki entry on Development setup.
This project was originally based on @percy/storybook.
FAQs
[](https://www.npmjs.com/package/@chanzuckerberg/axe-storybook-testing)  [!
The npm package @chanzuckerberg/axe-storybook-testing receives a total of 6,041 weekly downloads. As such, @chanzuckerberg/axe-storybook-testing popularity was classified as popular.
We found that @chanzuckerberg/axe-storybook-testing demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.