forked from VKCOM/VKUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckbox.test.tsx
22 lines (21 loc) · 912 Bytes
/
Checkbox.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import React, { useState } from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import '@testing-library/jest-dom/extend-expect';
import { baselineComponent } from '../../testing/utils';
import { Checkbox } from './Checkbox';
describe('Checkbox', () => {
baselineComponent(Checkbox);
it('handles change', () => {
const CheckboxController = () => {
const [checked, setChecked] = useState(false);
return <Checkbox checked={checked} onChange={(e) => setChecked(e.target.checked)}>check</Checkbox>;
};
render(<CheckboxController />);
expect(screen.getByRole('checkbox')).not.toBeChecked();
userEvent.click(screen.getByText('check'));
expect(screen.getByRole('checkbox')).toBeChecked();
userEvent.click(screen.getByText('check'));
expect(screen.getByRole('checkbox')).not.toBeChecked();
});
});