Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

92
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda