- Introduction
- Quick start
- Philosophy
- Comparison
- Default behaviors
- Limitations
- Debugging runbook
- FAQ
- Mocking HTTP
- Mocking GraphQL
- Mocking WebSocket
- Integrations
- API
- CLI
- Best practices
- Recipes
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.