@accesslint/vitest 0.1.0 → 0.1.3

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.
Files changed (2) hide show
  1. package/README.md +88 -0
  2. package/package.json +3 -3
package/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # @accesslint/vitest
2
+
3
+ Accessibility assertions for Vitest. Adds a `toBeAccessible()` matcher powered by [AccessLint](https://accesslint.com) that checks for WCAG 2.1 Level A and AA violations.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install --save-dev @accesslint/vitest
9
+ ```
10
+
11
+ `vitest` >= 2.0 is required as a peer dependency.
12
+
13
+ ## Setup
14
+
15
+ Add `@accesslint/vitest` as a setup file in your Vitest config:
16
+
17
+ ```ts
18
+ // vitest.config.ts
19
+ import { defineConfig } from "vitest/config";
20
+
21
+ export default defineConfig({
22
+ test: {
23
+ setupFiles: ["@accesslint/vitest"],
24
+ },
25
+ });
26
+ ```
27
+
28
+ This automatically registers the `toBeAccessible()` matcher.
29
+
30
+ ### Manual registration
31
+
32
+ If you prefer to register the matcher yourself:
33
+
34
+ ```ts
35
+ import { accesslintMatchers } from "@accesslint/vitest/matchers";
36
+ import { expect } from "vitest";
37
+
38
+ expect.extend(accesslintMatchers);
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ Pass any DOM `Element` to `expect()` and call `toBeAccessible()`:
44
+
45
+ ```ts
46
+ const container = document.createElement("div");
47
+ container.innerHTML = '<img src="photo.jpg" alt="A photo">';
48
+
49
+ expect(container).toBeAccessible();
50
+ ```
51
+
52
+ The matcher scopes violations to descendants of the element you pass, so you can test components in isolation.
53
+
54
+ ### Disabling rules
55
+
56
+ To ignore specific rules, pass `disabledRules`:
57
+
58
+ ```ts
59
+ expect(container).toBeAccessible({
60
+ disabledRules: ["color-contrast"],
61
+ });
62
+ ```
63
+
64
+ ### Failure messages
65
+
66
+ When violations are found, the matcher reports each one with its rule ID, WCAG level, success criterion, description, and the selector of the offending element:
67
+
68
+ ```
69
+ Expected element to have no accessibility violations, but found 2:
70
+
71
+ img-alt [A] (1.1.1): Images must have alternate text
72
+ img
73
+
74
+ color-contrast [AA] (1.4.3): Text must have sufficient color contrast
75
+ p.subtitle
76
+ ```
77
+
78
+ ## What it checks
79
+
80
+ The matcher runs 92 WCAG 2.1 Level A and AA rules via `@accesslint/core`, covering images, forms, ARIA attributes, color contrast, landmarks, links, tables, document language, and more.
81
+
82
+ ## TypeScript
83
+
84
+ Types are included. Importing the package augments Vitest's `expect` with `toBeAccessible()` automatically.
85
+
86
+ ## License
87
+
88
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@accesslint/vitest",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "Accessibility assertions for Vitest — toBeAccessible() matcher powered by AccessLint",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -8,10 +8,10 @@
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git+https://github.com/AccessLint/core.git"
11
+ "url": "git+https://github.com/AccessLint/vitest.git"
12
12
  },
13
13
  "bugs": {
14
- "url": "https://github.com/AccessLint/core/issues"
14
+ "url": "https://github.com/AccessLint/vitest/issues"
15
15
  },
16
16
  "type": "module",
17
17
  "exports": {