redux-devtools/packages/redux-devtools-ui/tests/Slider.test.tsx

42 lines
983 B
TypeScript
Raw Normal View History

2019-01-03 16:00:55 +03:00
import React from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
2019-01-03 16:00:55 +03:00
import { Slider } from '../src';
describe('Slider', function () {
2019-01-03 16:00:55 +03:00
it('renders correctly', () => {
const { container } = render(
<Slider
onChange={() => {
// noop
}}
/>
);
expect(container.firstChild).toMatchSnapshot();
2019-01-03 16:00:55 +03:00
});
it('renders with props', () => {
const { container } = render(
2019-01-03 16:00:55 +03:00
<Slider
label="Hi"
min={1}
max={10}
value={5}
disabled
onChange={() => {
// 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 change event', () => {
const onChange = jest.fn();
render(<Slider value={1} onChange={onChange} />);
2019-01-03 16:00:55 +03:00
fireEvent.change(screen.getByRole('slider'), { target: { value: '2' } });
expect(onChange).toHaveBeenCalled();
expect(onChange).toHaveBeenCalledWith(2);
2019-01-03 16:00:55 +03:00
});
});