How can I simulate a change to an input field?

import { shallow } from 'enzyme'
const props = { onClick: jest.fn() }
const wrapper = <App {...props} />
const domNode = document.querySelector('#root')
const component = shallow(wrapper, domNode)

const selector = '.fld-input'
const eventName = 'change'
const eventInfo = { target: { value: 'hello' }}
component.find(selector).simulate(eventName, eventInfo)
expect(component.value()).toBe('hello')

Last updated

Was this helpful?