Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,12 @@ make a partial match passing a regular expression, or by using
aria-describedby="t1"
/>
<span id="t1" role="presentation">The logo of Our Company</span>
<img
src="logo.jpg"
data-testid="logo2"
alt="Company logo"
aria-description="The logo of Our Company"
/>
```

```js
Expand All @@ -606,6 +612,9 @@ expect(getByTestId('logo')).not.toHaveAccessibleDescription('Company logo')
expect(getByTestId('logo')).toHaveAccessibleDescription(
'The logo of Our Company',
)
expect(getByTestId('logo2')).toHaveAccessibleDescription(
'The logo of Our Company',
)
```

<hr />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"aria-query": "^5.0.0",
"chalk": "^3.0.0",
"css.escape": "^1.5.1",
"dom-accessibility-api": "^0.5.6",
"dom-accessibility-api": "^0.6.3",
"lodash": "^4.17.15",
"redent": "^3.0.0"
},
Expand Down
20 changes: 20 additions & 0 deletions src/__tests__/to-have-accessible-description.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ describe('.toHaveAccessibleDescription', () => {
}).toThrow(/expected element not to have accessible description/i)
})

it('works with aria-description attribute', () => {
const {queryByTestId} = render(`
<img src="logo.jpg" data-testid="logo" alt="Company logo" aria-description="The logo of Our Company">
`)

const logo = queryByTestId('logo')
expect(logo).not.toHaveAccessibleDescription('Company logo')
expect(logo).toHaveAccessibleDescription('The logo of Our Company')
expect(logo).toHaveAccessibleDescription(/logo of our company/i)
expect(logo).toHaveAccessibleDescription(
expect.stringContaining('logo of Our Company'),
)
expect(() => {
expect(logo).toHaveAccessibleDescription("Our company's logo")
}).toThrow(/expected element to have accessible description/i)
expect(() => {
expect(logo).not.toHaveAccessibleDescription('The logo of Our Company')
}).toThrow(/expected element not to have accessible description/i)
})

it('handles multiple ids', () => {
const {queryByTestId} = render(`
<div>
Expand Down