button.spec.jsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import React from 'react';
  2. import {mount, shallow} from 'enzyme';
  3. import Button from 'app/components/button';
  4. describe('Button', function() {
  5. let routerContext = TestStubs.routerContext();
  6. it('renders', function() {
  7. let component = shallow(
  8. <Button priority="primary" size="large">
  9. Button
  10. </Button>
  11. );
  12. expect(component).toMatchSnapshot();
  13. });
  14. it('renders react-router link', function() {
  15. let component = shallow(<Button to="/some/route">Router Link</Button>, routerContext);
  16. expect(component).toMatchSnapshot();
  17. });
  18. it('renders normal link', function() {
  19. let component = shallow(
  20. <Button href="/some/relative/url">Normal Link</Button>,
  21. routerContext
  22. );
  23. expect(component).toMatchSnapshot();
  24. });
  25. it('renders disabled normal link', function() {
  26. let component = shallow(
  27. <Button href="/some/relative/url">Normal Link</Button>,
  28. routerContext
  29. );
  30. expect(component).toMatchSnapshot();
  31. });
  32. it('calls `onClick` callback', function() {
  33. let spy = jest.fn();
  34. let component = mount(<Button onClick={spy} />, routerContext);
  35. component.simulate('click');
  36. expect(spy).toHaveBeenCalled();
  37. });
  38. it('does not call `onClick` on disabled buttons', function() {
  39. let spy = jest.fn();
  40. let component = mount(<Button onClick={spy} disabled />, routerContext);
  41. component.simulate('click');
  42. expect(spy).not.toHaveBeenCalled();
  43. });
  44. });