Could someone tell me how to test this simple behavior, I've been trying to solve this for a lot of time now, and I hope I'm just missing something because a change event should be easy to test.
I tried calling onChange
instead of simulate
, wrapper.update()
, await new Promise(resolve => setTimeout(resolve))
no result.
import * as React from 'react';
import { Form, Field } from 'react-final-form';
import { mount } from 'enzyme';
it('change event', () => {
const wrapper = mount(
<Form onSubmit={jest.fn()}>
{() => (
<Field name="name">
{({input}) => <input value={input.value} onChange={input.onChange} />}
</Field>
)}
</Form>
)
expect(wrapper.find('input').prop('value')).toEqual('');
wrapper.find('input').simulate('change', { target: { value: 'blue cheese' } } );
expect(wrapper.find('input').prop('value')).toEqual('blue cheese');
});
This test fails miserably:
Expected value to equal:
"blue cheese"
Received:
""