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

289
Views
Jest prueba el método de gancho de reacción para obtener una mejor cobertura de código

Tengo un componente que establece el estado según el método onClick de la siguiente manera:

 const [active, setActive] = React.useState(0); <button type="button" onClick={() => {setActive(() => index); inner.fc(index)}} key={inner.id}>{inner.title}</button>

La prueba en sí es:

 it('Should test setActive index of button', (): void => { const setIndex = jest.fn(() => 1); let tree = create(<button type="button" onClick={setIndex} key='1'>1 button</button>); const button = tree.root.findByType('button') button.props.onClick() expect(setIndex()).toBe(1); });

Esto pasa, pero cuando miro el informe de cobertura, ¿marca el método setActive como no cubierto? ¿Cómo pruebo ese método React.useState correctamente?

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!