DEV Community

Krishnan S
Krishnan S

Posted on

1 3

How can we test useState hooks inside a void function with jest and enzyme?

I'm new to unit-testing and writing test cases using jest and enzyme in React. Can someone please help me to write the test case for this example?

const [open, setOpen] = useState(false);
const handleClose = () => {
    setOpen(!open);
}

//this handleClose is an onClick event
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more