2019-01-03 16:00:55 +03:00
|
|
|
import React from 'react';
|
2021-10-22 07:18:03 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
import userEvent from '@testing-library/user-event';
|
2019-01-03 16:00:55 +03:00
|
|
|
import { Button } from '../src';
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
describe('Button', function () {
|
2019-01-03 16:00:55 +03:00
|
|
|
it('renders correctly', () => {
|
2021-10-22 07:18:03 +03:00
|
|
|
const { container } = render(<Button>Text</Button>);
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle the click event', () => {
|
|
|
|
const onClick = jest.fn();
|
2021-10-22 07:18:03 +03:00
|
|
|
render(<Button onClick={onClick}>ClickMe</Button>);
|
2019-01-03 16:00:55 +03:00
|
|
|
|
2021-10-22 07:18:03 +03:00
|
|
|
userEvent.click(screen.getByRole('button'));
|
|
|
|
expect(onClick).toHaveBeenCalled();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
});
|