Skip to content

vitest-axe

Axe violations matchers for Vitest.

Install

sh
npm i -D axe-core @chialab/vitest-axe
sh
yarn add -D axe-core @chialab/vitest-axe
sh
pnpm add -D axe-core @chialab/vitest-axe

Usage

Use a Vitest setup file to add the matchers to the test runner.

ts
export default {
    test: {
        setupFiles: ['./test/setup.ts'],
    },
}
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();
    });
});

Released under the MIT License.