Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
Unit test function in React / Jest with proper coverage

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!