Skip to content

Commit

Permalink
Update Readme and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amanmahajan7 committed Jan 3, 2024
1 parent 369a2af commit 8f68a89
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
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
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

0 comments on commit 8f68a89

Please sign in to comment.