Questions tagged [usefaketimers]

10 questions
2
votes
0 answers

Test gets stuck when using jest.useFakeTimers() during a database async operation

I'm trying to do some tests where I need to use fake timers. I'm not showing the complete test here because the issue can be reduced to this. The point is that when I debug, it gets stuck on the await triggerRepository. If I remove the fake timers…
1
vote
0 answers

Why is the behavior of `jest.useFakeTimers` different when called inside vs. outside of `beforeEach` in React Native

Overview I encountered different behaviors of jest.useFakeTimers when it is called inside beforeEach versus called outside. Reproducible Examples // Foo.tsx import * as React from 'react'; import {View} from 'react-native'; const Foo: React.FC =…
Fanchen Bao
  • 3,310
  • 1
  • 21
  • 34
1
vote
1 answer

Sinon fake timers and syncing ticks with unpredictable timers to guarantee order of execution

I'm using Sinon fake timers to test some functions containing timers. The problem is that the tested function uses several asynchronous calls before the timer is called, and I find it hard to sync the test case so that clock.tickAsync() is…
JHH
  • 8,567
  • 8
  • 47
  • 91
1
vote
0 answers

How to assert on callback when using jest.useFakeTimers

I'm trying to understand how to correctly unit test a custom debounce method we have: // function we want to test function debounce(func, wait = 100) { let timeout; return (...args) => { clearTimeout(timeout); timeout = setTimeout(() =>…
A. Masson
  • 2,287
  • 3
  • 30
  • 36
0
votes
0 answers

Testing with Jest FakeTimers

I'm having a problem testing a particular component. It is a wrapper that includes a progress bar which in turn receives a now number prop (0-100 percentage) which dictates the position of the bar. In the test I've recruited Jest's fakeTimers to…
Adrian Bartholomew
  • 2,506
  • 6
  • 29
  • 37
0
votes
1 answer

jest.UseFakeTimers() / jestjest.runAllTimers() don't work

I've just started the topic of testing in react, I've been introduced to some aspects of how and why to test in React. Everything's been fine until I wanted to use jest.UseFakeTimers() and jest.runAllTimers() to test if component state changes after…
Veanty
  • 33
  • 5
0
votes
2 answers

Timeout simulation not working with testing-library and useFakeTimers

I'm working on a vueJS component that allows to display a modal after 5 seconds. the component works well as expected.