-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathform.test.js
36 lines (28 loc) · 1.14 KB
/
form.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React from 'react';
import 'react-testing-library/cleanup-after-each';
import {render} from 'react-testing-library';
// automatically extend expect
// This can also be added to Jest's setupTestFrameowrkScriptFile file to be
// available in all tests
import 'jest-axe/extend-expect';
// import axe and a matcher for a11y violations
import {axe, toHaveNoViolations} from 'jest-axe';
import {Form} from '../src/form';
// extend expect
// We don't need this if we simply import `jest-axe/extend-expect`
// expect.extend(toHaveNoViolations);
describe('Form', () => {
// axe is async, so we need to make our test async
test('not accessible when no label', async () => {
const {container, debug} = render(<Form />);
// get the result of evaluating a11y with axe
const result = await axe(container.outerHTML);
// use jest-axe's matcher to assert that our form is accessible
expect(result).not.toHaveNoViolations();
});
test('accessibility when label', async () => {
const {container, debug} = render(<Form isAccessible={true} />);
const result = await axe(container.outerHTML);
expect(result).toHaveNoViolations();
});
});