Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

when using delay and jest modern fakeTimers it seems to be using a real delay #58

Open
trajano opened this issue Dec 18, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@trajano
Copy link

trajano commented Dec 18, 2022

I was trying to introduce a "delay" on the processing for the response so I used the { delay } option. But noticed my timings are getting randomized.

Upon closer inspection it seemed that there was a real delay once I increased the amount of time I was processing. So it is not respecting the modern jest.useFakeTimers

Ideally I was hoping it will use the setTimeout that is provided by jest so I can control the behaviour, but it is using the real thing.

@trajano
Copy link
Author

trajano commented Dec 18, 2022

The work around for anyone interested is

Given

.post("http://asdf.com/refresh", response, {delay: 1000});

Replace with

.post("http://asdf.com/auth", 
  new Promise((resolve) => setTimeout(() => resolve(response), 1000)))

@wheresrhys wheresrhys added the bug Something isn't working label Jul 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants