LOGOMock Service Worker
  1. Api
  2. setupWorker()
  3. printHandlers()

printHandlers()

Prints the list of currently active request handlers into the browser's console.

Example

1// handlers.js
2import { setupWorker, rest } from 'msw'
3
4const worker = setupWorker(
5 rest.get('/user/:userId', (req, res, ctx) => {
6 return res(ctx.json({ id: req.params.userId }))
7 }),
8)
9
10worker.start()

To list all the active request handlers run the following command:

1worker.printHandlers()

Consider storing the worker instance on the global window object to access its methods anytime from the browser.

Each request handler outputted into the console contains the following information:

  • Request method (GET) and path (/user/:userId).
  • Declaration frame (handlers.js@5:8) you can click to navigate to the place in your code where you declare this handler.