What I would do here is to firstly check that the input element exists:
it('verifies that an input element is rendered', () => {
expect(wrapper.exists('input')).toBeTruthy();
});
Then, with that verified, separately verify the onChange
function exists. I'm not someone who supports having multiple verifications in a single it
statement simply because if any of the expect
statements trigger a failure, then all expect
statements below that are never carried out. So I'd use a separate it
as follows:
it('verifies that an onChange function is set`, () => {
expect(typeof wrapper.find('input').prop('onChange')).toBe('function');
});
Another option is to set a mock function for your onChange
prop and verify that it's invoked correctly as follows:
const testOnChange = jest.fn();
const wrapper = mount(<App onChange={testOnChange} />);
it('verifies that the onChange function is invoked', () => {
wrapper.find('input').prop('onChange')();
expect(testOnChange.mock.calls).toHaveLength(1);
});