storybook/docs/snippets/react/accessibility-testing-with-jest-axe.js.mdx
2022-03-18 19:22:17 +01:00

24 lines
544 B
Plaintext

```js
// MyComponent.test.js
import { render } from '@testing-library/react';
import { composeStories } from '@storybook/testing-react';
import { axe, toHaveNoViolations } from 'jest-axe';
import * as MyComponentStories from './MyComponent.stories';
const { Accessible } = composeStories(MyComponentStories);
expect.extend(toHaveNoViolations);
test('Example accessibility test', async () => {
const { container } = render(<Accessible />);
const AxeResults = await axe(container);
expect(AxeResults).toHaveNoViolations();
});
```