forked from zoltantothcom/Design-Patterns-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.test.js
More file actions
52 lines (42 loc) · 1.46 KB
/
Button.test.js
File metadata and controls
52 lines (42 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React from 'react';
import renderer from 'react-test-renderer';
import { shallow } from 'enzyme';
import 'jest-styled-components';
import Button from '../../src/components/Button';
import { renderWithLightTheme } from '../helpers';
import { renderWithDarkTheme } from '../helpers';
describe('<Button /> component', () => {
const mockClick = jest.fn();
const buttonEl = <Button label="Test Button" id="test" onClick={mockClick} />;
let button;
beforeEach(() => {
button = shallow(buttonEl);
});
it('renders without crashing', () => {
expect(button).toBeTruthy();
});
it('has styled-component rendered classes', () => {
const tree = renderer.create(buttonEl).toJSON();
expect(tree.props.className).toBeDefined();
});
it('renders with a LIGHT theme', () => {
const tree = renderWithLightTheme(buttonEl).toJSON();
expect(tree).toMatchSnapshot();
});
it('renders with a DARK theme', () => {
const tree = renderWithDarkTheme(buttonEl).toJSON();
expect(tree).toMatchSnapshot();
});
it('has the passed label', () => {
const buttonChilren = button.getElement().props.children;
expect(buttonChilren.type).toBe('span');
expect(buttonChilren.props.children).toEqual('Test Button');
});
it('has the passed id', () => {
expect(button.getElement().props.id).toEqual('test');
});
it('responds to click event', () => {
button.simulate('click');
expect(mockClick.mock.calls.length).toEqual(1);
});
});