-
-
Notifications
You must be signed in to change notification settings - Fork 130
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
Use mswjs/interceptors as interceptors layer for Nock #425
Comments
Hi, @mikicho. I appreciate you reaching out. Interceptors currently supports all means to make a request in Node.js, which includes the global Fetch API. If your testing uncovers some unexpected behaviors, it'd be a great opportunity for us to improve.
Sure. You can simulate a delay by awaiting a timeout promise in any import nodePreset from '@mswjs/interceptors/presets/node'
const interceptor = new BatchInterceptor({
name: 'my-interceptor',
interceptors: nodePreset
})
interceptor.on('request', async ({ request }) => {
await new Promise(resolve => setTimeout(resolve, 1000))
request.respondWith(new Response('Hello world')
}) This example will wait for 1000ms before responding to any intercepted request with a await delay(1000) Your usual Promise-based We can go through all the other use cases together if you could prepare a list of things Nock needs to implement. |
The socket-based interceptor has been merged to main! 🎉 The remaining Nock-compatibility tasks are tracked in #575. Looking forward to getting the rest done! |
I will close this in favor of #575. |
Hey,
As part of our efforts to add
fetch
support to Nock, we thought we could utilize this package to intercept the requests and add Nock's great API on top of it.I'm curious how we can simulate some exotic cases as we can do in Nock, like delay the connection.
More context: nock/nock#2397
The text was updated successfully, but these errors were encountered: