79456918

Date: 2025-02-21 09:45:50
Score: 1.5
Natty:
Report link

tldr: use jest.advanceTimersByTime(milliseconds);

The other solutions make sense, but did not work for me. In such case consider:

function toBeTested(){
    setTimeout(() => { /* do stuff later */}, 500);
}

it('does stuff later', () =>{
   toBeTested();
   jest.advanceTimersByTime(600);
   expect(/* things to be done */)
});

Docs: https://jestjs.io/docs/timer-mocks#advance-timers-by-time

Reasons:
  • Blacklisted phrase (1): did not work
  • Probably link only (1):
  • Has code block (-0.5):
Posted by: DBencz