Can anyone help me understand why the handler function in the HOC does not get called when the blur event is simulated in this jest test?
//MyInput.js
export const MyInput = (props) => (
<div>
...
<input onBlur={ props.onBlur } />
...
</div>
)
//HOC.js
export const withHOC = (SomeComponent) => {
return (props) => {
const handleBlur = () => {
console.log('this does not get called');
//do stuff
props.onBlur();
}
return <SomeComponent onBlur={handleBlur} />;
}
}
// test.js
describe('HOC', () => {
it('fires a callback in response to the blur event', () => {
const ModifiedInput = withHOC(MyInput);
const onBlurMock = jest.fn(() => {
console.log('this does get called');
});
const wrapper = mount(<ModifiedInput onBlur={onBlurMock} />);
const input = wrapper.find('input');
input.simulate('blur');
expect(onBlurMock).toHaveBeenCalled();
})
})