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

331
Views
¿Cómo probar una función que devuelve una función de flecha con Jest?

Tengo una función como esta:

 export const myFunc = (a, b ,callBack) => { const timer = setTimeout(() => { callBack(a+b); }, 10); return () => clearTimeout(timer); };

Puedo probar la función de devolución de llamada muy bien haciendo esto:

 jest.useFakeTimers(); describe('myFunc', () => { const callBack = jest.fn(); it('runs myFunc', () => { myFunc(1, 2, callBack); jest.runAllTimers(); expect(callBack).toHaveBeenCalledWith(3); });

Sin embargo, la última línea return () => clearTimeout(timer) nunca se prueba de alguna manera. El informe de broma solo dice que esta function not covered y la statement not covered . ¿Alguien puede decirme una forma de cubrir esta línea sin usar ninguna otra biblioteca de prueba externa como la enzima?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La función no se llama, por lo que no está cubierta.

Otra prueba sería:

 let cleanup = myFunc(1, 2, callBack); cleanup() jest.runAllTimers(); expect(callBack).not.toHaveBeenCalled();
about 4 years ago · Juan Pablo Isaza Report
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!