/
RadioButton.spec.jsx
41 lines (36 loc) · 1.4 KB
/
RadioButton.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
40
41
// @flow
import { mount } from 'enzyme/build';
import React from 'react';
import { RadioButton } from '..';
const label = 'Hello';
const id = 'some-id';
describe('RadioButton', () => {
describe('when props.checked is false', () => {
it('renders radio button correctly', () => {
const wrapper = mount(<RadioButton label={label} id={id} />);
expect(wrapper.state('checked')).toEqual(false);
expect(wrapper.find('.radioButtonLabel').text()).toEqual(label);
});
it('toggles correctly', () => {
const wrapper = mount(<RadioButton label={label} id={id} />);
const radioButton = wrapper.find('.radioButton');
radioButton.simulate('click');
expect(wrapper.state('checked')).toEqual(true);
radioButton.simulate('click');
expect(wrapper.state('checked')).toEqual(true);
});
});
describe('when props.checked is true', () => {
it('renders RadioButton correctly', () => {
const wrapper = mount(<RadioButton label={label} id={id} checked />);
expect(wrapper.state('checked')).toEqual(true);
expect(wrapper.find('.radioButtonLabel').text()).toEqual(label);
});
it('toggles correctly', () => {
const wrapper = mount(<RadioButton label={label} id={id} checked />);
const radioButton = wrapper.find('.radioButton');
radioButton.simulate('click');
expect(wrapper.state('checked')).toEqual(true);
});
});
});