Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

93
Vistas
How to test if inside a function in React Native Background Timer Jest

Hei, I;m new at react native testing, can someone help me solving this test. I'm never tried this before so im confuse to solve this function test, here's the code :

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

This code is use to running a timer, and for every 1 second, the timer will decrease (secs-1) from react native background timer.

my test code :

    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)
        })
      })

can someone help me for this help. I'm really appreciate the help, thankyou so much!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda