Network Mocking
Tools for mocking API responses without modifying your backend. Matched XHR/fetch requests return the mock response directly.
set_network_mock
Add a network mock rule. Matching requests will return the mocked response without hitting the network.
Parameters
Example
Tips
- Mocks intercept both
fetch()andXMLHttpRequestcalls. - Substring matching is the default. Use
isRegex: truefor complex patterns. - Mocks persist until explicitly removed or cleared.
- The
bodymust be a string. For JSON responses, stringify the object.
list_network_mocks
List all active network mock rules.
Parameters
Example
Tips
hitCountshows how many requests matched each mock — useful for verifying your mock was triggered.
remove_network_mock
Remove a specific network mock rule by its ID.
Parameters
Example
To remove all mock rules at once, use the unified clear tool with target: "network_mocks":
Call after a test scenario to ensure mocks don't leak into subsequent tests.