You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
addon-a11y: re-export axe-core (e.g. @storybook/addon-a11y/axe-core) to scan an opened surface from a test
#37094
@storybook/addon-a11y runs axe on document.body after a story and its tests finish. That covers a surface that is open at that moment, but there is no supported way to run the same check from inside a test, on one element, at the point the test has it open. A modal, sheet, popover or toast is closed when the story renders, so a test has to open it first.
To scan an opened surface explicitly (for example await expect(await findA11yViolations(dialog)).toEqual([])), a project has to import axe-core itself. axe-core is only a transitive dependency through the addon, so the project must add its own direct dependency and keep its version in step with the one the addon installs. Two copies of axe-core can also drift apart in version and rule set.
Proposal
Re-export axe-core from a subpath of the addon, for example:
This keeps one axe-core version, the one the addon is tested with, and needs no extra dependency.
Alternatives
A small helper that runs the addon's own run() with its configuration (parameters.a11y.config and options, plus the rules the addon always disables) against a given element, and returns the results. This would be the better fit if you prefer not to expose axe-core directly, because the rule configuration would then match what the addon applies automatically.
Documenting a11y.context with include: 'body' as the way to cover portals. That does not help with scanning at a chosen moment, or with tying a violation to one surface.
Happy to send a PR for the re-export if the subpath approach is acceptable.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Problem
@storybook/addon-a11yruns axe ondocument.bodyafter a story and its tests finish. That covers a surface that is open at that moment, but there is no supported way to run the same check from inside a test, on one element, at the point the test has it open. A modal, sheet, popover or toast is closed when the story renders, so a test has to open it first.To scan an opened surface explicitly (for example
await expect(await findA11yViolations(dialog)).toEqual([])), a project has to importaxe-coreitself.axe-coreis only a transitive dependency through the addon, so the project must add its own direct dependency and keep its version in step with the one the addon installs. Two copies ofaxe-corecan also drift apart in version and rule set.Proposal
Re-export
axe-corefrom a subpath of the addon, for example:This keeps one
axe-coreversion, the one the addon is tested with, and needs no extra dependency.Alternatives
run()with its configuration (parameters.a11y.configandoptions, plus the rules the addon always disables) against a given element, and returns the results. This would be the better fit if you prefer not to exposeaxe-coredirectly, because the rule configuration would then match what the addon applies automatically.a11y.contextwithinclude: 'body'as the way to cover portals. That does not help with scanning at a chosen moment, or with tying a violation to one surface.Happy to send a PR for the re-export if the subpath approach is acceptable.
All reactions