← Back to React, page 5

react-0092 · Hard senior

How do you build accessibility checks into a React workflow with axe-core, linting and manual testing, and what can automation not catch?

Combine layers: eslint-plugin-jsx-a11y while coding, axe-core in component tests (for example through jest-axe or vitest-axe) and in end-to-end runs, and manual checks with keyboard and a screen reader. Automation finds mechanical issues such as missing labels, missing alt text, duplicate ids and bad ARIA, but only part of all problems. It cannot judge whether alt text is meaningful, focus order makes sense, or a flow is usable, so manual testing remains required.

Full answer

Accessibility problems are cheapest to fix while code is written, so checks run at several points.

  1. Linting. eslint-plugin-jsx-a11y flags problems in JSX as you type: images without alt, clickable divs, invalid ARIA attributes and missing labels.
  2. Component tests. axe-core analyses a DOM and returns violations with rule ids, impact and the failing nodes. Wrappers such as jest-axe and vitest-axe provide toHaveNoViolations. Render the component in each important state (error messages shown, dialog open, menu expanded), because many problems appear only in states.
  3. End-to-end tests. Run axe on real pages in Playwright or Cypress, with real CSS, so rules that need layout and colors work. In jsdom, color contrast cannot be evaluated, so that rule is turned off in component tests.
  4. Manual testing. Use only the keyboard: can you reach and operate everything, is the focus visible, is the order logical, can you leave modals? Then test with a screen reader (VoiceOver, NVDA) on key flows. Check zoom to 200 percent and reduced motion.
  5. Process. Add a design system with accessible primitives, a checklist in pull request templates, CI that fails on new violations (with a reviewed baseline for old ones), and ownership for fixing.

What automation misses: whether labels and alt text are accurate, whether the heading structure tells the story, focus management after route changes, correct announcements, cognitive load, and custom widgets that behave wrongly despite valid markup. Automated tools find a minority of the possible issues, so passing axe is not proof of conformance to WCAG.

Interview framing: say you treat axe as a regression net, not a certificate.

The example audits a bad form and a fixed one with axe-core directly.

jsx
import axe from 'axe-core';
import { createRoot } from 'react-dom/client';

function BadForm() {
  return (
    <form>
      <input />
      <img src="/logo.png" />
      <button></button>
    </form>
  );
}

function GoodForm() {
  return (
    <form>
      <label>
        Email <input type="email" />
      </label>
      <img src="/logo.png" alt="Schoolabe logo" />
      <button type="submit">Subscribe</button>
    </form>
  );
}

async function audit(name, element) {
  const container = document.createElement('div');
  document.body.appendChild(container);
  const root = createRoot(container);
  root.render(element);
  await new Promise((resolve) => setTimeout(resolve, 30));
  const results = await axe.run(container, { rules: { 'color-contrast': { enabled: false } } });
  const ids = results.violations.map((v) => v.id).sort();
  console.log(name + ': ' + (ids.length ? ids.join(', ') : 'no violations'));
  root.unmount();
}

await audit('bad form', <BadForm />);
await audit('good form', <GoodForm />);

This ran axe-core 4 in a script on the box, with color contrast turned off because jsdom cannot compute it. Output of the run: bad form: button-name, image-alt, label good form: no violations

Key points

  • Layer checks: lint rules, axe in component and end-to-end tests, and manual keyboard and screen reader testing.
  • Test components in their important states, not only the default one.
  • Color contrast needs a real browser. jsdom cannot evaluate it.
  • Automation finds only part of the issues and cannot judge meaning or flow.
  • Use CI gates with a baseline, and accessible design system primitives.

Common mistakes

  • Treating a clean axe report as proof of accessibility.
  • Testing only the default state of components.
  • Relying on color contrast checks in jsdom.
  • Silencing rules globally to make the build pass.
  • Never testing with a keyboard or a screen reader.

Follow-ups

  • How would you add axe to a Playwright test suite?
  • How do you handle existing violations in a large codebase without blocking all work?
  • What would you check manually in a dialog component?

Tips

  • Call axe a regression net, not a certificate.
  • Name two things automation cannot check.
  • Mention testing states such as open menus and error messages.