Skip to main content

accesslint/jest

@accesslint/jest is a companion library for Testing Library that adds a synchronous toBeAccessible() matcher for Jest, covering WCAG 2.2 Level A and AA accessibility rules. Works under jsdom and happy-dom.

npm install --save-dev @accesslint/jest

Register the matcher once via setupFilesAfterEnv in your Jest config, then assert on any rendered element:

import {render} from '@testing-library/react'
import {LoginForm} from './LoginForm'

test('LoginForm is accessible', () => {
const {container} = render(<LoginForm />)
expect(container).toBeAccessible()
})

Violations are scoped to the element you pass, so components can be tested in isolation. Options include disabledRules, failOn impact thresholds, and snapshot baselines that auto-ratchet as you fix violations.

Check out @accesslint/jest's documentation for setup, options, and a migration guide from jest-axe.