resetHandlers()

将请求处理程序重置为初始列表。

调用签名

¥Call signature

server.resetHandlers() 方法可以在没有任何参数的情况下调用。完成后,所有 运行时请求处理程序(通过 server.use() 前置的)都将被删除。

¥The server.resetHandlers() method can be called without any arguments. When done so, all the Runtime request handlers (those prepended via server.use()) will be removed.

const server = setupServer(http.get('/resource', resolver))
 
server.use(http.post('/user', resolver))
 
server.resetHandlers()
// The "POST /user" runtime request handler is removed,
// and only the "GET /resource" initial request handler remains.

server.resetHandlers() 方法还接受作为其参数的可选请求处理程序列表。提供这样的列表时,传递给 setupServer() 的初始请求处理程序也将被删除,并且给定的请求处理程序列表将充当初始处理程序。

¥The server.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 setupServer() will also be removed, and the given list of request handlers would act as the initial handlers.

const server = setupServer(http.get('/resource', resolver))
server.use(http.post('/user', resolver))
 
server.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.

相关材料

¥Related materials