Skip to content

Commit

Permalink
Add vitest-axe documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardocavazza committed Mar 6, 2024
1 parent 14f0a23 commit 267ec92
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ export default defineConfig({
text: 'postcss-url-rebase',
link: '/guide/postcss-url-rebase',
},
{
text: 'vitest-axe',
link: '/guide/vitest-axe',
},
// {
// text: 'Write a plugin',
// link: '/guide/write-a-plugin',
Expand Down
58 changes: 58 additions & 0 deletions docs/guide/vitest-axe.md
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();
});
});
```
6 changes: 2 additions & 4 deletions packages/vitest-axe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ npm i @chialab/vitest-axe -D
yarn add @chialab/vitest-axe -D
```

## Usage
## Documentation

```js
import '@chialab/vitest-axe';
```
Read the documentation at [chialab.github.io/rna](https://chialab.github.io/rna/guide/vitest-axe).

---

Expand Down

0 comments on commit 267ec92

Please sign in to comment.