- 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
listHandlers()
Return the list of current request handlers.
Call signature
server.listHandlers()
This method accepts no arguments and returns a list of all handlers present on the server
object. It’s primarily designed for debugging and introspection purposes.
Filtering handlers
You can filter out the handlers to a particular type (e.g. only HTTP or only WebSocket handlers) by implementing the instanceof
check on the result of the .listHandlers()
function call.
For example, here’s how to log only HTTP handlers:
import { RequestHandler } from 'msw'
const handlers = server.listHandlers().filter((handler) => {
// This will include both `http.*` and `graphql.*` handlers
// while omitting and `ws.*` handlers.
return handler instanceof RequestHandler
})
console.log(handlers)
Respectively,
handler instanceof WebSocketHandler
returns onlyws
handlers.