-
-
Notifications
You must be signed in to change notification settings - Fork 133
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
Replace "request.respondWith()" with a Controller #431
Comments
Request controller interfaceinterface RequestController {
// Instruct the interceptor to perform the request as-is.
passthrough(): void
// Use the given response as the mock response for the request.
respondWith(response: Response): void
// Use the given error as the request error.
errorWith(error?: Error): void
// Abort the request.
// In some clients (ClientRequest) it's synonymous to ".errorWith()",
// in others (XMLHttpRequest) it's different.
abort(): void
} The request controller is exposed in the interceptor.on('request', ({ request, controller }) => {
controller.respondWith(new Response('hello world'))
}) The request controller can only handle the request once. Once any of its methods are called, calling methods on it again must throw an error (the same way calling |
Released: v0.33.0 🎉This has been released in v0.33.0! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
Instead of adding the
respondWith()
custom method on the Fetch APIRequest
representation of the intercepted request, expose that method alongside the request in the listener argument object.This also resembles the Service Worker's
fetch
event a bit more closely. Not that it has ever the intention but it's a nice little detail.The text was updated successfully, but these errors were encountered: