ctimmerm / axios-mock-adapter

Axios adapter that allows to easily mock requests
MIT License
3.47k stars 245 forks source link

Helper for delay in milliseconds #312

Closed prashanth-92 closed 1 year ago

prashanth-92 commented 3 years ago

232 Attempts to provide a helper for adding a delay in milliseconds. The test shows a way to use the method.

ctimmerm commented 3 years ago

Hi @prashanth-92! Thanks for your PR, but unfortunately your change doesn't actually introduce per-request delays. The added method instead sets the delay for all requests, so for example:

mock.delayInMs(200).onGet("/foo").reply(200);
mock.delayInMs(0).onGet("/bar").reply(200);

will cause no delay when a request to /foo is made.

prashanth-92 commented 3 years ago

Hey @ctimmerm, yes my solution is setting the delay in the MockAdapter directly. So it will work for one endpoint but if you set it again, it will get overridden

Just to see if I get this right, if we need to add it at an endpoint level, then we might need to introduce a state in the handlers per verb and then use delay it with a promise approach you mentioned in one of the comments.

prashanth-92 commented 3 years ago

@ctimmerm I have a revised approach with delay per request. Can you please review it?

prashanth-92 commented 3 years ago

Ping @ctimmerm If you have some time, please review this pull request

prashanth-92 commented 3 years ago

Hey @ctimmerm when you have time, please review this pull request. I would really appreciate it.

prashanth-92 commented 3 years ago

Please re-review @ctimmerm

prashanth-92 commented 2 years ago

Please re review.

prashanth-92 commented 2 years ago

@ctimmerm please review.

prashanth-92 commented 2 years ago

@ctimmerm Can you please re review?

jshall commented 2 years ago

I would also be interested to have withDelay() accept a function. This would allow me to create a function that generates a random delay in a specific range.

prashanth-92 commented 2 years ago

I would also be interested to have withDelay() accept a function. This would allow me to create a function that generates a random delay in a specific range.

The idea behind this pull request is to give a helper for introducing a delay time alone. Your new feature request can be addressed in another pull request. Feel free to open one.

phiter commented 1 year ago

Hey guys, is this getting merged or nah? I just found a use case where I need a delay for a specific request.

prashanth-92 commented 1 year ago

@ctimmerm If there are no concerns, can we merge this PR? I think it will be useful.

marcbachmann commented 1 year ago

hmm, a force push merged this accidentally and can't reopen. I'll merge this manually

marcbachmann commented 1 year ago

hah. reopen button shows up again.

edit: nope. didn't work

marcbachmann commented 1 year ago

Released as v1.22.0

jfstephe commented 1 year ago

marcbachmann, prashanth-92 - I'm a bit late to the party but there's no documentation and I think the typescript definitions are missing...

jfstephe commented 1 year ago

Also IMHO the API for this is now unintuitive (it looked like @ctimmerm had a good suggestion). Why the change to make this return the reply function rather than the request handler?

Glideh commented 1 year ago

Interested about that too. Need a doc & types up to date plz.

seriouslag commented 7 months ago

Interested about that too. Need a doc & types up to date plz.

I opened a PR to add types to replyWithDelay https://github.com/ctimmerm/axios-mock-adapter/pull/383