Skip to content

Commit 5abc103

Browse files
authored
Update a11y test to have an inaccessible form. (kentcdodds#31)
Co-authored-by: Gavriel Rachael-Homann <gavriel@gavriel.dev>
1 parent 7be0832 commit 5abc103

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/__tests__/a11y.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import {render} from '@testing-library/react'
33
import {axe} from 'jest-axe'
44

55
function InaccessibleForm() {
6+
// Form inputs must have an accessible name
7+
// Ref: 4.1.1 of W3C HTML Accessibility API Mappings 1.0
68
return (
79
<form>
8-
<input placeholder="email" />
10+
<input id="username" />
911
</form>
1012
)
1113
}
@@ -21,13 +23,11 @@ function AccessibleForm() {
2123

2224
test('inaccessible forms fail axe', async () => {
2325
const {container} = render(<InaccessibleForm />)
24-
try {
25-
expect(await axe(container)).toHaveNoViolations()
26-
} catch (error) {
27-
// NOTE: I can't think of a situation where you'd want to test that some HTML
28-
// actually _does_ have accessibility issues... This is only here for
29-
// demonstration purposes.
30-
}
26+
const axeResult = await axe(container)
27+
expect(() => expect(axeResult).toHaveNoViolations()).toThrow()
28+
// NOTE: I can't think of a situation where you'd want to test that some HTML
29+
// actually _does_ have accessibility issues... This is only here for
30+
// demonstration purposes.
3131
})
3232

3333
test('accessible forms pass axe', async () => {

0 commit comments

Comments
 (0)