Replies: 3 comments 9 replies
-
Hey, @fvanwijk. You can list the current request handlers using the worker.printHandlers()
// or
server.printHandlers() When called, this API will print the list of request handlers into the console, containing brief handler information and a stack trace pointing to the handler's declaration in your codebase. |
Beta Was this translation helpful? Give feedback.
-
The handler's nature is reproducible: they are applied when your runtime is instantiated. I see little practical use of persisting handlers—they don't hold an internal state to perstist. |
Beta Was this translation helpful? Give feedback.
-
My use case is a little different, but related. In my unit tests I want to figure out if I have outstanding (not called) one-time handlers which I added with I understand that server.printHandlers() prints these outstanding handlers. It would be nice if it would also return this list instead of just printing it (or if there would be a new method or property). In the meantime @fvanwijk and I could use this to keep track of the handlers ourselves: https://mswjs.io/docs/extensions/life-cycle-events |
Beta Was this translation helpful? Give feedback.
-
Is your feature request related to a problem? Please describe.
I would like to have a method on the worker that returns the currently registered handlers.
I think it could be just this simple line of code in setupWorker.ts:
Additional context
The request is partly related to another issue I have: when refreshing the browser, the registered handlers are gone.
I expect this has something to do with the handlers being registered in the client instance and not in the service worker.
The client is part of the application and reinitialized from scratch when refreshing the page.
When this feature request is implemented, we can maybe store the handlers in the browser (
sessionStorage
?) to make the handlers more persistent.Beta Was this translation helpful? Give feedback.
All reactions