Skip to content
intermediatePhase 39 · Accessibility

Accessibility Testing

Test accessibility with automated tools, manual testing, and screen readers.

45m
0 problems
Topic Progress0%

Automated Tools

Automated Tools

Automated tools catch common accessibility issues.

axe-core

// Install
npm install axe-core @axe-core/react

// React integration
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

if (process.env.NODE_ENV !== 'production') {
  import('@axe-core/react').then((axe) => {
    axe.default(React, ReactDOM, 1000);
  });
}

ReactDOM.render(<App />, document.getElementById('root'));

Jest Integration

// jest.config.js
module.exports = {
  setupFilesAfterSetup: ['@testing-library/jest-dom'],
};

// Form.test.js
import { render } from '@testing-library/react';
import { axe, toHaveNoViolations } from 'jest-axe';
import Form from './Form';

expect.extend(toHaveNoViolations);

describe('Form Accessibility', () => {
  it('should have no axe violations', async () => {
    const { container } = render(<Form />);
    const results = await axe(container);
    expect(results).toHaveNoViolations();
  });
});

Playwright Integration

// accessibility.spec.js
const { test, expect } = require('@playwright/test');
const AxeBuilder = require('@axe-core/playwright').default;

test('page has no accessibility violations', async ({ page }) => {
  await page.goto('/');

  const accessibilityScanResults = await new AxeBuilder({ page })
    .analyze();

  expect(accessibilityScanResults.violations).toEqual([]);
});

CI Integration

# .github/workflows/a11y.yml
name: Accessibility Tests
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - run: npm ci
      - run: npm run test:a11y
      - run: npm run build
      - run: npx lighthouse http://localhost:3000 --only-categories=accessibility

Manual Testing

Manual Testing

Automated tools can't catch everything.

Keyboard Testing

  1. Tab through all interactive elements
  2. Check focus visibility
  3. Verify logical tab order
  4. Test keyboard shortcuts
  5. Ensure no keyboard traps

Screen Reader Testing

  1. Test with NVDA/VoiceOver
  2. Verify all content is announced
  3. Check landmarks and headings
  4. Test dynamic content announcements
  5. Verify form labels and errors

Visual Testing

  1. Check color contrast
  2. Verify text can be resized to 200%
  3. Test with different color modes
  4. Check focus indicators
  5. Verify content reflows at 320px width

Manual Testing Checklist

## Keyboard
- [ ] All interactive elements focusable
- [ ] Focus visible on all elements
- [ ] Tab order logical
- [ ] No keyboard traps
- [ ] Enter/Space activate buttons
- [ ] Escape closes modals

## Screen Reader
- [ ] Page title announced
- [ ] Landmarks announced
- [ ] Headings in order
- [ ] Images have alt text
- [ ] Form labels announced
- [ ] Errors announced

## Visual
- [ ] Contrast ratios pass
- [ ] Text resizable to 200%
- [ ] No content loss at 320px
- [ ] Focus indicators visible
- [ ] No flashing content

Axe and Lighthouse

Axe and Lighthouse

Axe Rules

// Common axe rules
const rules = {
  // Color contrast
  'color-contrast': { enabled: true },
  
  // Forms
  'label': { enabled: true },
  'aria-required-attr': { enabled: true },
  
  // Images
  'image-alt': { enabled: true },
  
  // Navigation
  'link-name': { enabled: true },
  'button-name': { enabled: true },
  
  // ARIA
  'aria-allowed-attr': { enabled: true },
  'aria-required-attr': { enabled: true },
};

Lighthouse Scores

# Run Lighthouse accessibility audit
npx lighthouse http://localhost:3000 --only-categories=accessibility

# Output
# Accessibility: 95/100
# 
# Issues:
# - [aria-*] attributes: 2 issues
# - Color contrast: 1 issue

Common Issues Found

Issue Tool Fix
Missing alt text axe, Lighthouse Add meaningful alt
Low contrast axe, Lighthouse Increase contrast ratio
Missing labels axe Add labels or aria-label
Empty buttons axe Add accessible name
Missing heading Lighthouse Add h1 element

Testing Strategy

  1. Automated: Run axe in CI/CD
  2. Manual: Test with screen readers
  3. Visual: Check contrast and zoom
  4. Keyboard: Navigate without mouse
  5. User Testing: Include disabled users

Practice Problems

0/3solved
Build Accessibility Testing Component

Create a reusable React component implementing Accessibility Testing. Include proper state management and accessibility.

Solution
// Production-ready component with:
// - Proper TypeScript types
// - Accessibility (ARIA)
// - Error boundaries
// - Loading states
// - Memoization where needed
Accessibility Testing Testing

Write unit and integration tests for Accessibility Testing using React Testing Library.

Solution
// Test coverage:
// 1. Rendering tests
// 2. Interaction tests
// 3. Edge case tests
// 4. Accessibility tests
Accessibility Testing Performance

Optimize Accessibility Testing for performance. Consider memoization, code splitting, and bundle size.

Solution
// Optimization techniques:
// 1. React.memo / useMemo / useCallback
// 2. Code splitting with lazy()
// 3. Virtual scrolling for lists
// 4. Image lazy loading
// 5. Bundle analysis

Quiz

1. What does axe-core test?

Question 1 options

2. Can automated tools catch all accessibility issues?

Question 2 options

3. What is the primary purpose of Accessibility Testing?

Question 3 options

4. What is a common mistake when implementing Accessibility Testing?

Question 4 options

Flashcards

Question

What is axe-core?

Answer

An automated accessibility testing engine that catches common WCAG violations.

Question

Why is manual testing needed?

Answer

Automated tools only catch ~30-40% of issues; manual testing covers the rest.

Question

What does Lighthouse test?

Answer

Performance, accessibility, SEO, and best practices for web pages.

Question

How do you test keyboard accessibility?

Answer

Tab through all elements, verify focus visibility, check logical tab order.

Question

What is Accessibility Testing?

Answer

Accessibility Testing is a key concept in frontend development.

Revision Notes

Key Takeaways

  • 1.Automated tools catch common issues but not everything
  • 2.Manual testing with screen readers is essential
  • 3.Integrate axe-core into CI/CD pipeline
  • 4.Test keyboard navigation separately
  • 5.Combine automated and manual testing for best coverage

Interview Tips

  • Explain the difference between automated and manual testing
  • Discuss how to integrate accessibility testing into CI/CD
  • Know common tools and their coverage

Cheat Sheet

Accessibility Testing Cheat Sheet

Automated

  • axe-core: WCAG violations
  • Lighthouse: Overall score
  • jest-axe: Unit tests

Manual

  • Keyboard navigation
  • Screen reader testing
  • Visual contrast check
  • Zoom to 200%

CI/CD

  • axe in unit tests
  • Lighthouse in pipeline
  • axe in Playwright

Coverage

  • Automated: 30-40%
  • Manual: 60-70%