-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathModeSwitch.test.tsx
More file actions
43 lines (35 loc) · 1.36 KB
/
ModeSwitch.test.tsx
File metadata and controls
43 lines (35 loc) · 1.36 KB
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
import React from 'react';
import { fireEvent, render } from '@testing-library/react';
import { ModeSwitch } from './ModeSwitch';
describe('ModeSwitch', () => {
const labelA = 'A';
const labelB = 'B';
const label = 'test';
const tooltip = 'tooltip';
it('should render', () => {
const result = render(
<ModeSwitch labelA={labelA} labelB={labelB} value={false} onChange={() => {}} label={label} tooltip={tooltip} />
);
expect(result.container.firstChild).not.toBeNull();
});
it('should call onChange when mode is changed', () => {
const onChange = jest.fn();
const result = render(
<ModeSwitch labelA={labelA} labelB={labelB} value={false} onChange={onChange} label={label} tooltip={tooltip} />
);
expect(result.container.firstChild).not.toBeNull();
const buttonA = result.getByText(labelA);
expect(buttonA).toBeInTheDocument();
const buttonB = result.getByText(labelB);
expect(buttonB).toBeInTheDocument();
fireEvent.click(buttonB);
expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledWith(true);
result.rerender(
<ModeSwitch labelA={labelA} labelB={labelB} value={true} onChange={onChange} label={label} tooltip={tooltip} />
);
fireEvent.click(buttonA);
expect(onChange).toHaveBeenCalledTimes(2);
expect(onChange).toHaveBeenCalledWith(false);
});
});