logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

button-test.js (2258B)


  1. import { shallow } from 'enzyme';
  2. import React from 'react';
  3. import renderer from 'react-test-renderer';
  4. import Button from '../button';
  5. describe('<Button />', () => {
  6. it('renders a button element', () => {
  7. const component = renderer.create(<Button />);
  8. const tree = component.toJSON();
  9. expect(tree).toMatchSnapshot();
  10. });
  11. it('renders the given text', () => {
  12. const text = 'foo';
  13. const component = renderer.create(<Button text={text} />);
  14. const tree = component.toJSON();
  15. expect(tree).toMatchSnapshot();
  16. });
  17. it('handles click events using the given handler', () => {
  18. const handler = jest.fn();
  19. const button = shallow(<Button onClick={handler} />);
  20. button.find('button').simulate('click');
  21. expect(handler.mock.calls.length).toEqual(1);
  22. });
  23. it('does not handle click events if props.disabled given', () => {
  24. const handler = jest.fn();
  25. const button = shallow(<Button onClick={handler} disabled />);
  26. button.find('button').simulate('click');
  27. expect(handler.mock.calls.length).toEqual(0);
  28. });
  29. it('renders a disabled attribute if props.disabled given', () => {
  30. const component = renderer.create(<Button disabled />);
  31. const tree = component.toJSON();
  32. expect(tree).toMatchSnapshot();
  33. });
  34. it('renders the children', () => {
  35. const children = <p>children</p>;
  36. const component = renderer.create(<Button>{children}</Button>);
  37. const tree = component.toJSON();
  38. expect(tree).toMatchSnapshot();
  39. });
  40. it('renders the props.text instead of children', () => {
  41. const text = 'foo';
  42. const children = <p>children</p>;
  43. const component = renderer.create(<Button text={text}>{children}</Button>);
  44. const tree = component.toJSON();
  45. expect(tree).toMatchSnapshot();
  46. });
  47. it('renders class="button--block" if props.block given', () => {
  48. const component = renderer.create(<Button block />);
  49. const tree = component.toJSON();
  50. expect(tree).toMatchSnapshot();
  51. });
  52. it('adds class "button-secondary" if props.secondary given', () => {
  53. const component = renderer.create(<Button secondary />);
  54. const tree = component.toJSON();
  55. expect(tree).toMatchSnapshot();
  56. });
  57. });