Problem: You’re using msw (@ApiMocking) to mock out HTTP calls during...


Problem: You’re using msw (@ApiMocking) to mock out HTTP calls during development and automated testing, and you want to dynamically change the mock responses for different scenarios.

Solution: Here are three options:

1. Read an environment variable in the handler that specifies what mock response to use.

2. Use playwright-msw package to specify a custom mock response in a test. (This is obviously @playwrightweb specific).

3. Create custom dev tools that change settings passed into msw. This is my preferred approach. It’s powerful and flexible. Example: https://switchboard-beta.vercel.app

Anyone have a different approach?

View original on X