vi-axe 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -0
- package/package.json +16 -16
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# vi-axe
|
|
2
|
+
|
|
3
|
+
### A modern fork / rewrite of jest-axe for vitest.
|
|
4
|
+
|
|
5
|
+
I'm aware that vitest-axe also exists, however it seems to be unmaintained.
|
|
6
|
+
|
|
7
|
+
[](http://npm.im/vi-axe)
|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
Custom Vitest matcher for [aXe](https://github.com/dequelabs/axe-core) to test accessibility in your components and pages.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add -D vi-axe
|
|
16
|
+
# or
|
|
17
|
+
npm install -D vi-axe
|
|
18
|
+
# or
|
|
19
|
+
yarn add -D vi-axe
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Setup
|
|
23
|
+
|
|
24
|
+
Configure Vitest so the `toHaveNoViolations` matcher is available in all tests. In your Vitest config (e.g. `vitest.config.ts`):
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { defineConfig } from "vitest/config";
|
|
28
|
+
|
|
29
|
+
export default defineConfig({
|
|
30
|
+
test: {
|
|
31
|
+
environment: "jsdom", // required for axe
|
|
32
|
+
setupFiles: ["vi-axe/extend-expect"],
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Alternatively, in a single test file:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import "vi-axe/extend-expect";
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
### Basic
|
|
46
|
+
|
|
47
|
+
Run axe on an HTML string or DOM element, then assert there are no violations:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { axe } from "vi-axe";
|
|
51
|
+
|
|
52
|
+
test("has no a11y violations", async () => {
|
|
53
|
+
const html = `<main><a href="https://example.com">Example</a></main>`;
|
|
54
|
+
const results = await axe(html);
|
|
55
|
+
expect(results).toHaveNoViolations();
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### With React Testing Library
|
|
60
|
+
|
|
61
|
+
Pass the rendered container (or any element) to `axe`:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { render } from "@testing-library/react";
|
|
65
|
+
import { axe } from "vi-axe";
|
|
66
|
+
|
|
67
|
+
test("component has no a11y violations", async () => {
|
|
68
|
+
const { container } = render(<MyComponent />);
|
|
69
|
+
const results = await axe(container);
|
|
70
|
+
expect(results).toHaveNoViolations();
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### With Vue Test Utils
|
|
75
|
+
|
|
76
|
+
Pass the wrapper element:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { mount } from "@vue/test-utils";
|
|
80
|
+
import { axe } from "vi-axe";
|
|
81
|
+
|
|
82
|
+
test("component has no a11y violations", async () => {
|
|
83
|
+
const wrapper = mount(MyComponent);
|
|
84
|
+
const results = await axe(wrapper.element);
|
|
85
|
+
expect(results).toHaveNoViolations();
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Custom configuration
|
|
90
|
+
|
|
91
|
+
Use `configureAxe` to create an axe runner with default options. You can pass [axe-core run options](https://github.com/dequelabs/axe-core/blob/develop/doc/API.md) and vi-axe-specific options:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { configureAxe } from "vi-axe";
|
|
95
|
+
|
|
96
|
+
const axe = configureAxe({
|
|
97
|
+
globalOptions: {
|
|
98
|
+
rules: [{ id: "link-name", enabled: false }],
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("custom axe run", async () => {
|
|
103
|
+
const results = await axe("<a href='#'></a>");
|
|
104
|
+
expect(results).toHaveNoViolations();
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Per-run options can be passed as the second argument:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
const results = await axe(html, {
|
|
112
|
+
rules: { "link-name": { enabled: false } },
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Filtering by impact level
|
|
117
|
+
|
|
118
|
+
To fail only for certain impact levels (e.g. critical/serious), use `impactLevels` in `configureAxe`. The matcher will then consider only violations with those impacts:
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
import { configureAxe } from "vi-axe";
|
|
122
|
+
|
|
123
|
+
const axe = configureAxe({
|
|
124
|
+
impactLevels: ["critical", "serious"],
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Requirements
|
|
129
|
+
|
|
130
|
+
- **Node**: >= 20
|
|
131
|
+
- **Vitest** with **jsdom** (or another DOM environment); axe needs a DOM to run.
|
|
132
|
+
|
|
133
|
+
Color contrast rules are disabled by default in vi-axe because they do not work reliably in jsdom.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vi-axe",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Modern Vitest matcher for aXe for testing accessibility using axe-core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"a11y",
|
|
@@ -33,21 +33,21 @@
|
|
|
33
33
|
"lodash.merge": "4.6.2"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@testing-library/react": "
|
|
37
|
-
"@testing-library/vue": "
|
|
38
|
-
"@types/lodash.merge": "
|
|
39
|
-
"@types/node": "
|
|
40
|
-
"@types/react": "
|
|
41
|
-
"@types/react-dom": "
|
|
42
|
-
"@vue/test-utils": "
|
|
43
|
-
"jsdom": "
|
|
44
|
-
"react": "
|
|
45
|
-
"react-dom": "
|
|
46
|
-
"typescript": "
|
|
47
|
-
"unplugin-isolated-decl": "
|
|
48
|
-
"vite": "
|
|
49
|
-
"vitest": "
|
|
50
|
-
"vue": "
|
|
36
|
+
"@testing-library/react": "16.3.2",
|
|
37
|
+
"@testing-library/vue": "8.1.0",
|
|
38
|
+
"@types/lodash.merge": "4.6.9",
|
|
39
|
+
"@types/node": "25.5.0",
|
|
40
|
+
"@types/react": "19.2.14",
|
|
41
|
+
"@types/react-dom": "19.2.3",
|
|
42
|
+
"@vue/test-utils": "2.4.6",
|
|
43
|
+
"jsdom": "28.1.0",
|
|
44
|
+
"react": "19.2.4",
|
|
45
|
+
"react-dom": "19.2.4",
|
|
46
|
+
"typescript": "5.9.3",
|
|
47
|
+
"unplugin-isolated-decl": "0.15.7",
|
|
48
|
+
"vite": "8.0.0",
|
|
49
|
+
"vitest": "4.1.0",
|
|
50
|
+
"vue": "3.5.30"
|
|
51
51
|
},
|
|
52
52
|
"engines": {
|
|
53
53
|
"node": ">= 20.0.0"
|