vitest-axe
Install
sh
npm i -D axe-core @chialab/vitest-axesh
yarn add -D axe-core @chialab/vitest-axesh
pnpm add -D axe-core @chialab/vitest-axeUsage
Use a Vitest setup file to add the matchers to the test runner expectation API.
Also, make sure to include typings for the matchers in the tsconfig.json file.
ts
export default {
test: {
setupFiles: ['./test/setup.ts'],
},
}ts
import matchers from '@chialab/vitest-axe';
import { expect } from 'vitest';
expect.extend(matchers);json
{
"compilerOptions": {
// ...
"types": ["@chialab/vitest-axe/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();
});
});