/
Radio.spec.tsx
48 lines (38 loc) · 1.21 KB
/
Radio.spec.tsx
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
37
38
39
40
41
42
43
44
45
46
47
48
import React from 'react';
import { render, cleanup } from '@testing-library/react';
import { typeIs } from '@leafygreen-ui/lib';
import Radio from './Radio';
afterAll(cleanup);
describe('packages/Radio', () => {
const className = 'radio-test-class';
const { container } = render(
<Radio disabled value="option-1" className={className}>
Radio 1
</Radio>,
);
const radio = container.firstChild;
if (!typeIs.element(radio)) {
throw new Error('Could not find controlled container component');
}
const input = radio.firstChild;
if (!typeIs.input(input)) {
throw new Error('Could not find input element');
}
test(`renders "${className}" in the labels's class list`, () => {
expect(radio.classList.contains(className)).toBe(true);
});
test(`renders disabled radio when disabled prop is set`, () => {
expect(input.disabled).toBe(true);
expect(input.getAttribute('aria-disabled')).toBe('true');
});
test(`radio is checked when value is set`, () => {
render(
<Radio value="option-two" checked={true}>
Radio 2
</Radio>,
{ container },
);
expect(input.checked).toBe(true);
expect(input.getAttribute('aria-checked')).toBe('true');
});
});