- 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
- Using CDN
- Using custom "homepage" property
- Using local HTTPS
restoreHandlers()
Mark used one-time request handlers as unused.
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')