Override handlers at runtime between different clients #1475
Replies: 1 comment 2 replies
-
Hey, @almeida1492.
Yes, you need to lift the mocks state higher to achieve this. One common way to do that is to make the handlers dependent on the URL search parameters. // src/mocks/handlers.js
const params = new URLSearchParams(location.search)
const scenarioName = params.get('scenario')
const scenarios = {
success: [rest.get(...), rest.post(...)],
error: [rest.get(...)]
}
export const handlers = scenarioName ? scenarios[scenarioName] : scenarios.success Then, you can get the same mock behavior between different tabs. That won't support something like |
Beta Was this translation helpful? Give feedback.
-
I'm trying to implement a graphic interface to control the worker during a demo or integration test session. This interface would be attached to the app in the staging bundle and deployed on the environment where we test the system integration. The idea was to be able to turn on/off the interception or edit the mocked responses at runtime. By doing so, it would be possible to move on even if something in the back end is broken, saving us precious time.
The interface to control the worker would be served in a specific route (something like
/mocker
) that would be opened in a second tab different from the one with the app itself. Currently, the worker behaves in a per-client fashion, so if I have two tabs opened and I call.use()
in one of them, the change doesn't affect the other. Is it possible to change this behavior?Beta Was this translation helpful? Give feedback.
All reactions