I'm using Jest and Enzyme to test some React components (written using TypeScript). My old method was to use Enzyme's .simulate()
function to simulate a click, but this is being deprecated in favor of using instance prop functions (i.e. just using the component's onClick()
prop). However, I'm not sure how exactly to call the onClick()
function directly. Below is my code:
// Get the onClick function
const buttonOnClick = wrapper.find('#diffpicker-button').first().props().onClick;
// buttonOnClick could be a function or undefined, make sure its a function
if (!buttonOnClick) return;
// Assignment needed here, but to what?
let event: React.MouseEvent<Element, MouseEvent>;
// How to call it?
buttonOnClick(event);
I need to assign my event variable to pass to buttonOnClick()
, but what should I assign it to? What does an onClick event actually look like? Or, am I going about this all wrong?