I'm trying to test a default prop which is a function type but not sure how to do that with Jest mocking or spying:
Trying following test:
it("should call default toggle function prop on click of footer button", () => {
const wrapper = shallow(
<InfoModal
isOpen={true}
message="Primary message"
secondaryMessage="Secondary message"
/>
);
const footerButton = wrapper.find("ModalFooter Button");
const fn = jest.spyOn(wrapper.props(), "toggle");
footerButton.simulate("click");
wrapper.update();
expect(fn).toHaveBeenCalled();
});
It says TypeError: Cannot assign to read only property 'toggle' of object '[object Object]' where toggle is a function as default prop of InfoModal.
How can we test a function prop which has been set default not user defined.