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.