icon-button.test.jsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import React from 'react';
  2. import {shallow} from 'enzyme';
  3. import IconButton from '../../../src/components/icon-button/icon-button';
  4. import renderer from 'react-test-renderer';
  5. describe('IconButtonComponent', () => {
  6. test('matches snapshot', () => {
  7. const onClick = jest.fn();
  8. const title = <div>Text</div>;
  9. const imgSrc = 'imgSrc';
  10. const className = 'custom-class-name';
  11. const component = renderer.create(
  12. <IconButton
  13. className={className}
  14. img={imgSrc}
  15. title={title}
  16. onClick={onClick}
  17. />
  18. );
  19. expect(component.toJSON()).toMatchSnapshot();
  20. });
  21. test('triggers callback when clicked', () => {
  22. const onClick = jest.fn();
  23. const title = <div>Text</div>;
  24. const imgSrc = 'imgSrc';
  25. const componentShallowWrapper = shallow(
  26. <IconButton
  27. img={imgSrc}
  28. title={title}
  29. onClick={onClick}
  30. />
  31. );
  32. componentShallowWrapper.simulate('click');
  33. expect(onClick).toHaveBeenCalled();
  34. });
  35. });