Accepted answer

You can't spy handleClick event handler since it's defined in functional scope, it's private.

Your best test component behavior rather than implementation, such as what method is called inside the event handler, you should not go to mock and assert whether these methods are called, but what changes have occurred, such as what happens to the component, UI, DOM tree, etc.

But in your example, the handleClick event handler does not do anything, just calls console.log, then you can only assert whether the console.log is called indirectly assert whether the handleclick is called.

// arrange
const logSpy = jest.spyOn(console, 'log')
// act
// ...
// assert

Related Query

More Query from same tag