wagtail/client/src/components/Button/Button.test.js

40 lines
989 B
JavaScript
Raw Normal View History

import React from 'react';
import { shallow } from 'enzyme';
import Button from './Button';
describe('Button', () => {
it('exists', () => {
expect(Button).toBeDefined();
});
it('basic', () => {
expect(shallow(<Button />)).toMatchSnapshot();
});
it('#children', () => {
expect(shallow(<Button>To infinity and beyond!</Button>)).toMatchSnapshot();
});
it('#accessibleLabel', () => {
expect(shallow(<Button accessibleLabel="I am here in the shadows" />)).toMatchSnapshot();
});
it('#icon', () => {
expect(shallow(<Button icon="test-icon" />)).toMatchSnapshot();
});
it('#icon changes with #isLoading', () => {
expect(shallow(<Button icon="test-icon" isLoading={true} />)).toMatchSnapshot();
});
it('is clickable', () => {
const onClick = jest.fn();
shallow(<Button onClick={onClick} />).simulate('click', {
preventDefault() {},
stopPropagation() {},
});
expect(onClick).toHaveBeenCalledTimes(1);
});
});