I am trying to write a jest test for my inputBox component that include a button. Have a function 'onClick' as a prop inside this component.
<inputBox
placeholder={'Type here..'}
onClick={() => {inputRef.current.blur()}}
button={true}
ref={inputRef}
/>
I want to test the event 'inputBox is blur once I click the button'. Below is the test code:
it('invokes blur after click button',() => {
const onBlurSpy = jest.fn();
const { getAllByRole } = render(inputBox);
fireEvent.click(getAllByRole('button'))
expect(onBlurSpy).toHaveBeenCalled();
});
Receive below error:
expect(jest.fn()).toHaveBeenCalled()
Expected number of calls: >= 1
Received number of calls: 0
Any idea for this?