/
radio-button.js
31 lines (27 loc) · 1.01 KB
/
radio-button.js
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
//Test that components work with fields that pass target.checked and target.value
import React from 'react';
import Form from '../src/form';
import { mount } from 'enzyme';
const Input = ({ error, ...props }) => (
<div>
{error ? <p className="error">{error}</p> : null}
<input {...props} />
</div>
);
test('Input works with radio buttons', () => {
const wrapper = mount(
<Form>
<Input name="lightbulb" type="radio" value="on" checked />
<Input name="lightbulb" type="radio" value="off" />
</Form>
);
wrapper.find('[type="radio"]').last().simulate('change', {
target: { name: 'lightbulb', value: 'off', type: 'radio' },
});
const radios = wrapper.find('[type="radio"]');
// because we aren't intelligently managing this radio group the value gets overwritten
expect(radios.first().props().value).toEqual('off');
expect(radios.first().props().checked).toEqual(true);
expect(radios.last().props().value).toEqual('off');
expect(radios.last().props().checked).toEqual(undefined);
});