Modify many handlers at once? #753
-
Hi there again, I was asking last time about modifying the delay globally, i figured out how to make this work but now I'm wondering if i can modify many handlers at once to add values for the context for example. This would be an example scenario:
Does this make sense? or is it too late to modify the handlers at that point? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hey, @Geddard. Thanks for reaching out. Take a look at the updated Custom response composition recipe. It features a globally defined delay set on all mocked responses. You can transform handlers as you wish, just be careful not to dive too deep into the internals.
Response transformations are bound to the resolver function. Once you've called msw/src/handlers/RequestHandler.ts Line 93 in 8a816e0 I wouldn't recommend modifying these instances directly, as you'd be coupling your customization logic with the library's internals way too close. The recommended way is still to write either a custom context utility or response composition. |
Beta Was this translation helpful? Give feedback.
Hey, @Geddard. Thanks for reaching out.
Take a look at the updated Custom response composition recipe. It features a globally defined delay set on all mocked responses.
You can transform handlers as you wish, just be careful not to dive too deep into the internals.
Response transformations are bound to the resolver function. Once you've called
rest[method]
/graphql[method]
, the resolver's logic is hoisted under the returnedRequestHandler
instance:msw/src/handlers/RequestHandler.ts
Line 93 in 8a816e0
I wouldn't recommend modifying these instances…