-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to add a delay for a specific response? #232
Comments
Since you can reply with a promise, you can use that in combination with setTimeout to have per-request delays: mock.onGet('/any').reply(function(config) {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve([201, null]);
}, 2000);
});
}); If it's something you need to do often, you could write a helper function for it: const withDelay = (delay, response) => config => {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve(response);
}, delay);
});
});
// And then use it:
mock.onGet('/any').reply(withDelay(2000, [201, null])); |
@ctimmerm Thanks for the tip! But don't you think it would be better to add this option to the adapter itself? |
It would definitely be nice if we could do something like this: mock.onGet('/any').delay(1000).reply((config) => {
return [200];
}); So we don't have to wrap the entire response function with a Promise... |
I opened a PR to add types to replyWithDelay |
I mean something like this:
The text was updated successfully, but these errors were encountered: