npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

axe-testing-library

v0.2.0

Published

Extensions for automated aXe accessibility testing for popular test tooling

Downloads

13

Readme

axe-testing-library

Extensions for automated aXe accessibility testing for popular test tooling.

Features

  • Test matchers for Jest, Vitest, and Playwright
  • One-line setup
  • Customizable with full access to aXe's run options if needed
  • TypeScript types included

Support for more testing tools like Cypress, Puppeteer, Jasmine, and Mocha are planned to be added!

Installation

npm install --save-dev axe-testing-library

This library assumes you have already installed the dependencies required by the test framework you are using. For Jest and Vite, you must be using JSDOM as the test environment. This is on by default with Jest, but Vitest requires a configuration change.

Usage

This library provides an entrypoint for each supported testing framework. Import the one you need.

Jest

import { toBeAccessible } from "axe-testing-library/jest";

expect.extend({ toBeAccessible });

test("should be accessible", async () => {
  const htmlString = `
    <main>
      <h1>Hello World</h1>
      <img src="example.jpg" alt="Example image">
      <button>Click</button>
    </main>
  `;

  await expect(htmlString).toBeAccessible();
});

// Usage with React Testing Library
import { render } from "@testing-library/react";

test("should work with react", async () => {
  const { container } = render(<MyComponent />);
  await expect(container).toBeAccessible();
});

Vitest

import { toBeAccessible } from "axe-testing-library/vitest";
import { it, expect } from "vitest";

expect.extend({ toBeAccessible });

it("should be accessible", async () => {
  const htmlString = `
    <main>
      <h1>Hello World</h1>
      <img src="example.jpg" alt="Example image">
      <button>Click</button>
    </main>
  `;
  await expect(htmlString).toBeAccessible();
});

A note about JSDOM

aXe internally creates a canvas instance when it runs, so you may see not implemented warnings in your console:

Error: Not implemented: HTMLCanvasElement.prototype.getContext (without installing the canvas npm package)

You can install a mock yourself, or mock them yourself:

// vitest.setup.ts
import { vi } from "vitest";
HTMLCanvasElement.prototype.getContext = vi.fn();

// jest.setup.ts
HTMLCanvasElement.prototype.getContext = jest.fn();

Playwright

import { toBeAccessible } from "axe-testing-library/playwright";
import { test, expect as baseExpect } from "@playwright/test";

const expect = baseExpect.extend({ toBeAccessible });

test("should be accessible", async ({ page }) => {
  await expect(page).toBeAccessible();
});

Example Output

For each accessibility violation you have, axe-testing-library will report the violation message along with a link to the rule. It also provide the rule id.

axe testing library output with violation message, and link to rule and its rule id

Configuration

Pass axe run options to customize checks:

// Turn off the region rule
await expect(document.body).toBeAccessible({
  rules: { region: { enabled: false } },
});

You can see the full list of rules here.

Contributing

See CONTRIBUTING.md for how to report issues or submit changes.

License

MIT © Peak Software