`extend-to-be-announced` is a utility package providing custom Jest and Vitest matchers, specifically `toBeAnnounced`, for robustly testing ARIA live regions. It aims to simplify accessibility testing by abstracting away the complexities of how assistive technologies handle live region updates, preventing common false positives associated with simply checking DOM text content. The package is currently at version 2.0.0 and receives updates as needed, particularly when underlying dependencies or testing frameworks evolve. It differentiates itself by leveraging `aria-live-capture` internally to precisely detect actual announcements, ensuring tests reflect true user experience rather than just DOM state. This approach helps developers write more reliable and accurate accessibility tests, especially for dynamic content updates.
npm install extend-to-be-announcedVerified import paths — ran on the pinned version, not inferred.
Demonstrates the basic usage of `toBeAnnounced` matcher for both Jest and Vitest, showing how to test for announced updates and avoid false positives with initial content.
For Jest, add `aria-live-capture` to your `transformIgnorePatterns` in `jest.config.js`. Example for pnpm: `transformIgnorePatterns: ['/node_modules/.pnpm/(?!(aria-live-capture)@)']`.
Utilize `extend-to-be-announced`'s `toBeAnnounced` matcher, which correctly distinguishes between initial content and subsequent announcements. Always ensure the live region content is updated *after* initial render to trigger an announcement.
Pass the `includeShadowDom: true` option to the `register` function when setting up the matcher, e.g., `import { register } from 'extend-to-be-announced/jest/register'; register({ includeShadowDom: true });`Modify your Jest configuration's `transformIgnorePatterns` to include `aria-live-capture`. For example: `transformIgnorePatterns: ['/node_modules/.pnpm/(?!(aria-live-capture)@)']` (adjust for your package manager).
Ensure you have imported the setup file in your test setup configuration (e.g., `setupFilesAfterEnv` for Jest, `setupFiles` for Vitest): `import 'extend-to-be-announced/jest';` or `import 'extend-to-be-announced/vitest';`.