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

91
Views
Cómo probar si está dentro de una función en React Native Background Timer Jest

Hola, soy nuevo en las pruebas nativas de reacción, ¿alguien puede ayudarme a resolver esta prueba? Nunca probé esto antes, así que estoy confundido para resolver esta prueba de función, aquí está el código:

 export const startTimer = (setSecondLeft: Function): void => { reactNativeBackgroundTimer.runBackgroundTimer(() => { setSecondLeft(secs => { if (secs > 0) { return secs - 1; } else if (secs === 0) { reactNativeBackgroundTimer.stopBackgroundTimer(); } }); }, 1000); };

Este código se usa para ejecutar un temporizador, y por cada 1 segundo, el temporizador disminuirá (segundos-1) desde el temporizador de fondo nativo de reacción.

mi código de prueba:

 import reactNativeBackgroundTimer from 'react-native-background-timer'; jest.mock('react-native-background-timer',() =>{ return{ runBackgroundTimer: jest.fn(), stopBackgroundTimer : jest.fn() } }) const runTimer = jest.spyOn(reactNativeBackgroundTimer,'runBackgroundTimer') describe('Timer Handler Unit Test',()=>{ const setSecondLeft = jest.fn() it('Should be called',()=>{ startTimer(setSecondLeft) expect(runTimer).toBeCalled() }) it('Should return secs - 1',()=>{ const secs = 10 runTimer() expect(startTimer(setSecondLeft)).toBe(9) }) })

alguien me puede ayudar para esta ayuda. Realmente aprecio la ayuda, ¡muchas gracias!

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!