Skip to main content

toBeAccessibleLink()

A link widget provides an interactive reference to a resource.

The target resource can be either external or local, i.e., either outside or within the current page or application.

Usage

Syntax

import { render, screen } from '@testing-library/react'

test('alert', () => {
render(
<a href="https://veiko.github.io/jest-a11y" role="alert">
Hey, listen!
</a>,
)

expect(screen.getByRole('link')).toBeAccessibleLink()
})

Test Summary

The toBeAccessibleLink matcher tests the following:

✓ element has role link
✓ element activates on Enter

DOM Examples

WAI-ARIA Roles, States, and Properties

<!-- ✓ element has role link implicit -->
<a href="https://veiko.github.io/jest-a11y">click me</button>

<!-- ✓ element has role link -->
<div href="https://veiko.github.io/jest-a11y" role="link">click me</div>

<!-- ❌ element has role link -->
<div onclick="window.location='https://veiko.github.io/jest-a11y'">click me</div>