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

373
Views
React Hooks: Timeout occurred during unit testing waitForValueToChange
export function useTimer(initValue: number, isProceed: boolean) {
  const [value, setter] = useState(initValue)

  useEffect(() => {
    setter(initValue)
    const interval = setInterval(() => {
      if (isProceed && value > 0) setter((c) => c - 1)
      else if (value < 0) {
        clearInterval(interval)
      }
    }, 1000)
    return () => {
      clearInterval(interval)
    }
  }, [initValue, value, isProceed])

  return {
    seconds:
      value > 0
        ? `${Math.floor(value / 60)}:${value % 60 < 10 ? '0' : ''}${value % 60}`
        : '',
    resetTimer: () => setter(initValue),
  }
}

  test('InitialCountState < 0', async () => {
    const { hydrate, result, waitForValueToChange } = renderHook(() =>
      useTimer(InitialCountState, isStartTimer)
    )
    InitialCountState = -1
    isStartTimer = true

    hydrate()
    await waitForValueToChange(() => result.current.seconds)
    expect(result.current.seconds).toBe('')
  })

Timed out in waitForValueToChange after 1000ms.

Failed to resolve failure result during hooks test. It's said that it failed because it was over time, but I don't know how to solve it. Is there a good way?

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!