Closed tiger9502 closed 5 years ago
Can you write up some pseudo code to explain what you mean? Why do you need the delayed response?
sure... let's say you do fetch.mockResponse(JSON.stringify('my server is really slow'), 500) to mock a slow server that takes 500 ms to respond
Apart from an edge case of slow servers - you'd probably want to mock most responses so they are fast so I'm uneasy changing the simpler API. Maybe it could be a new method as opposed to changing the current API. Something like fetch.mockDelayedResponse?
What would the Pseudo code look like if you used a function as an argument instead?
it can be used to mock a simple webserver.
something like this:
let username = 'user'; let email = 'test@test.com';
fetch.mockResponse(() => JSON.stringify({ message: Welcome, ${username}! Your email is ${email}
}));
and you can reassign username and email later and not worry about the mock.
On Sun, Jun 17, 2018 at 11:06 PM Jeff Lau notifications@github.com wrote:
Apart from an edge case of slow servers - you'd probably want to mock most responses so they are fast so I'm uneasy changing the simpler API. Maybe it could be a new method as opposed to changing the current API. Something like fetch.mockDelayedResponse?
What would the Pseudo code look like if you used a function as an argument instead?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jefflau/jest-fetch-mock/issues/77#issuecomment-397950774, or mute the thread https://github.com/notifications/unsubscribe-auth/ACgW-O6PJhnkMQXxCa0kSaWLNfGvGVvRks5t90NcgaJpZM4UrF26 .
have you seen this PR by @lsimone?
https://github.com/jefflau/jest-fetch-mock/pull/75
Would this kind of implementation be similar to what you were suggesting?
I guess this use case would be covered by my PR:
const delayResponse = (res, delay) => new Promise((resolve, reject) => setTimeout(() => resolve(res), delay))
fetch.mockResponse(delayResponse(JSON.stringify('my server is really slow'), 500))
hi Jeff, yeah that'd be just fine. Thanks Jeff and Isimone!
Hi @tiger9502, @jefflau ! Is this issue has been resolved ?
Thanks
Is this or #75 going to move forward, @jefflau and @lsimone? This library is perfect, but this is blocking me as well. Is there a way I can help somehow?
I want to provide the new PR but I didn't have time so far. I'll try to find it ASAP in the next 2 weeks!
Is there any update on this? From my usage this is the last piece of the puzzle.
I'd love to get this in, but I'm also a little busy these days. The discussion on this implementation is over here: https://github.com/jefflau/jest-fetch-mock/pull/75 and I think the general use case of either taking an object or a promise is a decent generalised API which would enable async support.
@lsimone is there any chance you will get some time to implement what we discussed back in June?
@jefflau I'll try to deliver it this Sunday (or before if I can)
Legend!
@tomevans18 I found time to push my last commits. It can be merged IMO.
This is now merged and published. Please take a look and test it out for us! I will close this issue soon after
@lsimone epic work! @jefflau thanks for the update 👍
I will start using this and feedback any issues.
@tomevans18 Working smoothly so far?
Closing this issue. Assuming everything is working fine :)
this is to enable mocking a delayed response.
maybe even consider adding a second argument in mockResponse as response time in ms.