Skip to content

Commit 1fb156c

Browse files
authored
feat: toHaveAccessibleDescription supports aria-description (#565)
1 parent b64b953 commit 1fb156c

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

Diff for: README.md

+9
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,12 @@ make a partial match passing a regular expression, or by using
594594
aria-describedby="t1"
595595
/>
596596
<span id="t1" role="presentation">The logo of Our Company</span>
597+
<img
598+
src="logo.jpg"
599+
data-testid="logo2"
600+
alt="Company logo"
601+
aria-description="The logo of Our Company"
602+
/>
597603
```
598604

599605
```js
@@ -606,6 +612,9 @@ expect(getByTestId('logo')).not.toHaveAccessibleDescription('Company logo')
606612
expect(getByTestId('logo')).toHaveAccessibleDescription(
607613
'The logo of Our Company',
608614
)
615+
expect(getByTestId('logo2')).toHaveAccessibleDescription(
616+
'The logo of Our Company',
617+
)
609618
```
610619

611620
<hr />

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"aria-query": "^5.0.0",
8686
"chalk": "^3.0.0",
8787
"css.escape": "^1.5.1",
88-
"dom-accessibility-api": "^0.5.6",
88+
"dom-accessibility-api": "^0.6.3",
8989
"lodash": "^4.17.15",
9090
"redent": "^3.0.0"
9191
},

Diff for: src/__tests__/to-have-accessible-description.js

+20
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ describe('.toHaveAccessibleDescription', () => {
5757
}).toThrow(/expected element not to have accessible description/i)
5858
})
5959

60+
it('works with aria-description attribute', () => {
61+
const {queryByTestId} = render(`
62+
<img src="logo.jpg" data-testid="logo" alt="Company logo" aria-description="The logo of Our Company">
63+
`)
64+
65+
const logo = queryByTestId('logo')
66+
expect(logo).not.toHaveAccessibleDescription('Company logo')
67+
expect(logo).toHaveAccessibleDescription('The logo of Our Company')
68+
expect(logo).toHaveAccessibleDescription(/logo of our company/i)
69+
expect(logo).toHaveAccessibleDescription(
70+
expect.stringContaining('logo of Our Company'),
71+
)
72+
expect(() => {
73+
expect(logo).toHaveAccessibleDescription("Our company's logo")
74+
}).toThrow(/expected element to have accessible description/i)
75+
expect(() => {
76+
expect(logo).not.toHaveAccessibleDescription('The logo of Our Company')
77+
}).toThrow(/expected element not to have accessible description/i)
78+
})
79+
6080
it('handles multiple ids', () => {
6181
const {queryByTestId} = render(`
6282
<div>

0 commit comments

Comments
 (0)