- Introduction
- Getting started
- Philosophy
- Comparison
- Limitations
- Debugging runbook
- FAQ
- Basics
- Concepts
- Network behavior
- Integrations
- API
- CLI
- Best practices
- Recipes
- Cookies
- Query parameters
- Response patching
- Polling
- Streaming
- Network errors
- File uploads
- Responding with binary
- Custom worker script location
- Global response delay
- GraphQL query batching
- Higher-order resolver
- Keeping mocks in sync
- Merging Service Workers
- Mock GraphQL schema
- Remote Request Interception
- Using CDN
- Using custom "homepage" property
- Using local HTTPS
resetHandlers()
Reset request handlers to the initial list.
Call signature
The worker.resetHandlers()
method can be called without any arguments. When done so, all the Runtime request handlers (those prepended via worker.use()
) will be removed.
const worker = setupWorker(http.get('/resource', resolver))
worker.use(http.post('/user', resolver))
worker.resetHandlers()
// The "POST /user" runtime request handler is removed,
// and only the "GET /resource" initial request handler remains.
The worker.resetHandlers()
method also accepts an optional list of request handlers spread as its arguments. When such a list is provided, the initial request handlers passed to setupWorker()
will also be removed, and the given list of request handlers would act as the initial handlers.
const worker = setupWorker(http.get('/resource', resolver))
worker.use(http.post('/user', resolver))
worker.resetHandlers(http.patch('/book/:bookId', resolver))
// Both the runtime "POST /user" and the initial "GET /resource"
// request handlers are removed, and only the "PATCH /book/:bookId"
// request handler remains.