Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions code/addons/a11y/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@
"dependencies": {
"@storybook/addon-highlight": "workspace:*",
"@storybook/test": "workspace:*",
"axe-core": "^4.2.0",
"vitest-axe": "^0.1.0"
"axe-core": "^4.2.0"
},
"devDependencies": {
"@storybook/global": "^5.0.0",
Expand All @@ -82,7 +81,8 @@
"react-dom": "^18.2.0",
"react-resize-detector": "^7.1.2",
"resize-observer-polyfill": "^1.5.1",
"typescript": "^5.7.3"
"typescript": "^5.7.3",
"vitest-axe": "^0.1.0"
},
"peerDependencies": {
"storybook": "workspace:^"
Expand Down
11 changes: 7 additions & 4 deletions code/addons/a11y/src/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Source: https://github.com/chaance/vitest-axe/blob/main/src/to-have-no-violations.ts
import * as matchers from 'vitest-axe/matchers';

import type { AfterEach } from 'storybook/internal/types';

import { expect } from '@storybook/test';
Expand All @@ -10,7 +7,7 @@ import { A11Y_TEST_TAG } from './constants';
import type { A11yParameters } from './params';
import { getIsVitestRunning, getIsVitestStandaloneRun } from './utils';

expect.extend(matchers);
let vitestMatchersExtended = false;

// eslint-disable-next-line @typescript-eslint/naming-convention
export const experimental_afterEach: AfterEach<any> = async ({
Expand Down Expand Up @@ -54,6 +51,12 @@ export const experimental_afterEach: AfterEach<any> = async ({
*/
if (getIsVitestStandaloneRun()) {
if (hasViolations) {
if (!vitestMatchersExtended) {
const { toHaveNoViolations } = await import('vitest-axe/matchers');
expect.extend({ toHaveNoViolations });
vitestMatchersExtended = true;
}

// @ts-expect-error - todo - fix type extension of expect from @storybook/test
expect(result).toHaveNoViolations();
Comment on lines 60 to 61

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding a type assertion or updating @storybook/test types to properly handle the toHaveNoViolations matcher

}
Expand Down