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')
PreviousHow can I simulate a click on a rendered component?NextHow can I check if a sub-component was rendered?
Last updated
Was this helpful?