-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathFormButton.spec.jsx
executable file
·39 lines (35 loc) · 1.12 KB
/
FormButton.spec.jsx
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
import React from 'react';
import { shallow, mount } from 'enzyme';
import ButtonForm from './ButtonForm';
describe('ButtonForm', () => {
it('renders', () => {
const wrapper = shallow(<ButtonForm />);
expect(wrapper.find('.ButtonForm').length).toBeTruthy();
});
it('renders children', () => {
const wrapper = shallow(
<ButtonForm>
<div id="test" />
</ButtonForm>
);
expect(wrapper.find('#test').length).toBeTruthy();
});
it('accepts classes passed in', () => {
const wrapper = shallow(
<ButtonForm className="test" isActive isDisabled />
).render();
expect(wrapper.hasClass('test')).toBe(true);
expect(wrapper.hasClass('btn--active')).toBe(true);
expect(wrapper.hasClass('btn--disabled')).toBe(true);
});
it('onclick focuses and fires prop', () => {
const clickFunc = jest.fn();
const testString = 'TestString';
const wrapper = mount(
<ButtonForm onClick={clickFunc}>{testString}</ButtonForm>
);
wrapper.simulate('click');
expect(document.activeElement.innerHTML).toBe(testString);
expect(clickFunc).toHaveBeenCalled();
});
});