-
Notifications
You must be signed in to change notification settings - Fork 512
/
Checkbox.unit.tsx
29 lines (22 loc) · 992 Bytes
/
Checkbox.unit.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
import React from 'react';
import {fireEvent, render} from '../../shared/test-util';
import {Checkbox} from './Checkbox';
it('it calls onChange handler when user clicks on checkbox', () => {
const onChange = jest.fn();
const {getByText} = render(<Checkbox checked={true} onChange={onChange} label="Checkbox" />);
const checkbox = getByText('Checkbox');
fireEvent.click(checkbox);
expect(onChange).toBeCalledWith(false);
});
it('it does not call onChange handler when read-only', () => {
const onChange = jest.fn();
const {getByText} = render(<Checkbox checked={true} readOnly={true} onChange={onChange} label="Checkbox" />);
const checkbox = getByText('Checkbox');
fireEvent.click(checkbox);
expect(onChange).not.toBeCalled();
});
it('it cannot be instantiated without handler when not readonly', () => {
expect(() => {
render(<Checkbox checked={true} label="Checkbox" />);
}).toThrow('A Checkbox element expect an onChange attribute if not readOnly');
});