
Security News
PEP 810 Proposes Explicit Lazy Imports for Python 3.15
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
@chanzuckerberg/axe-storybook-testing
Advanced tools
[](https://www.npmjs.com/package/@chanzuckerberg/axe-storybook-testing)  [!
Command line interface for running axe-core accessibility tests 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
To use:
storybook build
command.axe-storybook
, which will analyze the static build.To make this as easy as possible to use, we recommend adding a script to your package.json that does this in one step.
// In package.json
"scripts": {
"storybook:axe": "storybook build && 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 | Values | Description |
---|---|---|---|
--browser | chromium | chromium, firefox, webkit | Which browser to run the tests |
--build-dir | storybook-static | path | Storybook static build directory |
--failing-impact | all | all, minor, moderate, serious, critical | The lowest impact level that should be considered a failure |
--headless | true | boolean | Whether to run headlessly or not |
--pattern | .* | regex pattern | Only run tests that match a component name pattern |
--reporter | spec | spec, dot, nyan, tap, landing, list, progress, json, json-stream, min, doc, markdown, xunit | How to display the test run. Can be any built-in Mocha reporter. |
--reporter-options | string | Options to pass to the mocha reporter. Especially useful with the xunit reporter - e.g. --reporter-options output=./filename.xml | |
--storybook-address | url | Deprecated! Use --storybook-url instead. | |
--storybook-url | url | Url to a running Storybook to test against. Alternative to --build-dir , which will be ignored if this is set. | |
--timeout | 2000 | number | Deprecated! Use the timeout story parameter instead. |
For example, to run non-headlessly in 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 specific Axe rules on a story by using the disabledRules
parameter.
// SomeComponent.stories.jsx
export const 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'],
},
};
Set whether errors for a story will fail the test suite or not.
Valid options are:
off
- the story will be skipped and axe will not run on it. This is the same as setting skip: true
.warn
- axe errors will be printed, but won't fail the test suite. Stories with this set will show up as pending.error
(default) - axe errors will fail the test suite for a story.// .storybook/preview.js
export const parameters = {
axe: {
mode: 'warn',
},
};
Allows use of any of the available axe.run
options. See the link for more details. When using runOptions.rules
in combination with disabledRules
, disabledRules
will always take precedent.
export const SomeStory = {
parameters: {
axe: {
runOptions: {
preload: true,
selectors: true,
...
}
}
};
Prevent axe-storybook-testing from running a story by using the skip
parameter. This is shorthand for setting mode: 'off'
.
// SomeComponent.stories.jsx
export const SomeStory = {
parameters: {
axe: {
skip: true,
},
},
};
Overrides global --timeout
for this specific test
// SomeComponent.stories.jsx
export const SomeStory = {
parameters: {
axe: {
timeout: 5000,
},
},
};
Deprecated!
Legacy way of waiting for a selector before running Axe.
Now we recommend using a Storybook play function to do the same thing.
// SomeComponent.stories.jsx
// Old, deprecated way.
export const SomeStory = {
parameters: {
axe: {
waitForSelector: '#some-component-selector',
},
},
};
// New, better way using a play function - https://storybook.js.org/docs/react/writing-stories/play-function
SomeStory.play = async () => {
await screen.findByText('some string');
};
axe-storybook-testing provides TypeScript types for the story parameters listed above.
Story parameters can be type checked by augmenting Storybook's Parameter
type:
// overrides.d.ts
import type { AxeParams } from '@chanzuckerberg/axe-storybook-testing';
declare module '@storybook/react' {
// Augment Storybook's definition of Parameters so it contains valid options for axe-storybook-testing
interface Parameters {
axe?: AxeParams;
}
}
Annotate your stories with the StoryObj
type, and your parameters will be type-checked!
// SomeComponent.stories.ts
export const SomeStory: StoryObj<Args> = {
parameters: {
axe: {
timeout: 5000,
},
},
};
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 17,317 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
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.