I have a functional component and I wanted to test it with mock function (simplified demonstration)
const remove = () => {
... do something
}
const removeButton = (props) => (
<Button onClick={() => remove()}>
Remove
</Button>
);
I tried with this test case
it('test remove button', () => {
const test = shallow(<removeButton/>)
const mockFunction = jest.fn()
test.instance().remove = mockFunction
test.find('Button').simulate('click')
expect(mockFunction).toHaveBeenCalled()
})
.instance().remove could not mock the function because it is out of scope. How would I mock the function remove ?