mocking-strategy
Test isolation strategies, Mock Service Worker, in-memory fakes, and preventing mock drift in integration tests.
SKILL.mdskills/mocking-strategy/SKILL.md
GitHubMocking Strategy & Test Isolation Protocol
Ensure tests remain fast and isolated without creating fragile or out-of-sync test simulations.
1. In-Memory Fakes Over Heavy Mocks
- Prefer writing lightweight in-memory fakes implementing the real repository interface over scattering complex mock expectations throughout test files.
- In-memory fakes maintain realistic state and allow testing business logic across multiple calls without coupling tests to implementation details.
2. Mock Service Worker for Network APIs
- Intercept network requests at the network layer using MSW rather than monkey-patching fetch or axios.
- Share MSW request handlers between unit tests, integration tests, and local browser development to guarantee consistency.
- Validate mock responses against production schema contracts to prevent mock drift.