I'm trying to simulate a click with jest & enzyme and I'm new to react's testing libraries.
My component is using Material UI.
Here's the part of my code I want to test:
<div>
<Typography className={classes.instructions}>
All steps completed - you're finished
</Typography>
<Button onClick={handleNext} className={classes.button}>
Next
</Button>
</div>
In this part, I want to test the button click
Here's what I've done so far:
let wrapper;
const handleNext = jest.fn();
beforeEach(() => {
wrapper = mount(<ModelStepper handleNext={handleNext}/>)
})
it("handleNext increment", () => {
const btn = wrapper.find(Button).at(1)
expect(handleNext).toBeCalledTimes(0);
btn.simulate("click");
expect(handleNext).toBeCalledTimes(1);
})
For some reason I'm not getting it to be clicked, I've already console logged the text of the button and it's the correct button I want to click.
Thanks!!