button.test.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* eslint-disable no-undef */
  2. import React from 'react';
  3. import { cleanup, fireEvent } from '@testing-library/react';
  4. import '@testing-library/jest-dom';
  5. import testWrapper from '../helpers/testWrapper';
  6. import Button from '../components/Button';
  7. import theme from '../helpers/theme';
  8. describe('Button component', () => {
  9. afterEach(cleanup);
  10. test('check button content', () => {
  11. const { getByText } = testWrapper(<Button>btn content</Button>);
  12. expect(getByText('btn content').textContent).toBe('btn content');
  13. });
  14. test('check button primary theme', () => {
  15. const { getByText } = testWrapper(
  16. <Button appearance="primary">btn content</Button>,
  17. );
  18. expect(getByText('btn content')).toHaveStyle(`
  19. background-color: ${theme.colors.primary};
  20. border-color: ${theme.colors.primary};
  21. color: white;
  22. `);
  23. });
  24. test('check click event', () => {
  25. let counter = 0;
  26. const handleClick = (): void => {
  27. counter += 1;
  28. };
  29. const { getByText } = testWrapper(
  30. <Button onClick={handleClick}>btn content</Button>,
  31. );
  32. fireEvent.mouseDown(getByText('btn content'));
  33. expect(counter).toBe(1);
  34. });
  35. test('check disable status', () => {
  36. const { getByText } = testWrapper(<Button isDisabled>btn content</Button>);
  37. expect(getByText('btn content')).toBeDisabled();
  38. });
  39. });