I am trying to test this toggle function with proper coverage in React / Jest:
const [toggle, setToggle] = React.useState<boolean>(true);
const handlePush = () => setToggle(toggle => !toggle);
it ('Should test the handleClick method for toggling', () => {
const handlePush = jest.fn(toggle => !toggle);
let tree = create(<button onClick={handlePush}>Menu</button>)
const button = tree.root.findByType('button')
button.props.onClick()
expect(handlePush).toHaveBeenCalledTimes(1);
});
This passes but the coverage still does not cover the handlePush() method? any idea's?