Using "ctx.delay" without arguments should add a realistic server response delay
See original GitHub issueIs your feature request related to a problem? Please describe.
Quite often you would want a mocked response to behave similar to the actual response in terms of response time. Real servers rarely reply to requests instantly, while using res()
would do so.
Describe the solution you’d like
Calling ctx.delay()
without arguments should implicitly create a random realistic response delay, similar to the one of the actual server.
rest.get('/numbers', (req, res, ctx) => {
return res(ctx.delay(), ctx.json([1, 2, 3])
})
Possible implementation
Check if the durationMs
argument is given to the delay()
function:
And if not, generate a random response delay number instead. Something similar to:
res.delay = durationMs || RANDOM_REALISTIC_RESPONSE_TIME
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
delay() - Api - Mock Service Worker Docs
Delays the response by the given duration (in ms). When no duration is provided, uses a random realistic server response time.
Read more >Mocking Error, Empty and Loading states with MSW
In this article, we take a look at how we can use MSW to mock these states ... It will also add a...
Read more >HAProxy version 2.6.7-5 - Configuration Manual
Defines a delay between SIGUSR1 and real soft-stop. Arguments : <time> is an extra delay (by default in milliseconds) after receipt of the ......
Read more >HAProxy version 2.0.28 - Configuration Manual - GitHub Pages
This parameter is used to enforce an upper bound on delay between the first ... The real use is for keep-alive connections sent...
Read more >API — Flask Documentation (2.2.x)
The function will be called without any arguments and its return value is ignored. ... When using flask run to start the development...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I will work on it!
default delay amount should be very short when running in node vs. when running in browser. Maybe 10ms and 600ms