restoreHandlers()
将使用的一次性请求处理程序标记为未使用。
调用签名
¥Call signature
const worker = setupWorker(
http.get('/resource', () => HttpResponse.json({ id: 'abc-123' }), {
once: true,
})
)
// The first request to "GET /resource" will be intercepted by
// the request handler above, and the mocked JSON response will be returned.
await fetch('/resource')
// Since the matching request handler above was marked as "{ once: true }"
// and has already handled a matching request, the subsequent requests to
// this resource will by bypassed and the original response will be returned.
await fetch('/resource')
// By calling the "worker.restoreHandlers()" method, you are marking all
// used one-time request handlers as unused so they can affect the network again.
worker.restoreHandlers()
// The matching one-time request handler was restored, so the mocked response
// will be returned again. Past this point, the handler is marked as used again.
await fetch('/resource')
相关材料
¥Related materials