-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14f0a23
commit 267ec92
Showing
3 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Vitest Axe matchers | ||
|
||
Axe violations matchers for Vitest. | ||
|
||
## Install | ||
|
||
::: code-group | ||
|
||
```sh[npm] | ||
npm i -D axe-core @chialab/vitest-axe | ||
``` | ||
|
||
```sh[yarn] | ||
yarn add -D axe-core @chialab/vitest-axe | ||
``` | ||
|
||
```sh[pnpm] | ||
pnpm add -D axe-core @chialab/vitest-axe | ||
``` | ||
|
||
::: | ||
|
||
## Usage | ||
|
||
Use a Vitest setup file to add the matchers to the test runner. | ||
|
||
::: code-group | ||
|
||
```ts[vitest.config.ts] | ||
export default { | ||
test: { | ||
setupFiles: ['./test/setup.ts'], | ||
}, | ||
} | ||
``` | ||
|
||
```ts[test/setup.ts] | ||
import matchers from '@chialab/vitest-axe'; | ||
import { expect } from 'vitest'; | ||
expect.extend(matchers); | ||
``` | ||
|
||
::: | ||
|
||
## Example | ||
|
||
```ts | ||
import { run as axe } from 'axe-core'; | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
describe('button', () => { | ||
test('accessibility', async () => { | ||
const button = document.createElement('button'); | ||
expect(await axe(button)).toHaveNoViolations(); | ||
}); | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters