redux-devtools/packages/redux-devtools-ui/test/SegmentedControl.test.tsx

35 lines
926 B
TypeScript
Raw Permalink Normal View History

2019-01-03 16:00:55 +03:00
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
2019-01-03 16:00:55 +03:00
import { SegmentedControl } from '../src';
describe('SegmentedControl', function () {
2019-01-03 16:00:55 +03:00
it('renders correctly', () => {
const { container } = render(
2019-01-03 16:00:55 +03:00
<SegmentedControl
values={['Button1', 'Button2', 'Button3']}
selected="Button1"
disabled={false}
onClick={() => {
// noop
}}
2019-01-03 16:00:55 +03:00
/>
);
expect(container.firstChild).toMatchSnapshot();
2019-01-03 16:00:55 +03:00
});
it('should handle the click event', () => {
const onClick = jest.fn();
render(
2019-01-10 21:51:14 +03:00
<SegmentedControl
values={['Button1', 'Button2', 'Button3']}
selected="Button1"
disabled={false}
onClick={onClick}
/>
2019-01-03 16:00:55 +03:00
);
userEvent.click(screen.getByRole('button', { name: 'Button1' }));
expect(onClick).toHaveBeenCalled();
2019-01-03 16:00:55 +03:00
});
});