Accepted answer

You are assigning myMethod to a mock function which doesn't do anything, not even your original myMethod. When you are creating jest.fn(), what it basically does is creating a dummy mock function which doesn't do anything. So when you call wrapper.find('ChildComponent').props().myMethod(), it just call that function but not your myMethod.

What you might want to do is to spy on your method instead.

jest.spyOn(ParentComponent.prototype, 'myMethod'); // ParentComponent.prototype.myMethod is now a mock function

expect(ParentComponent.prototype.myMethod).toHaveBeenCalledTimes(1); // it works

Related Query

More Query from same tag