Tests Can Pass While Mock Data Ships — The Prevention Pattern
Jest is excellent at testing code behavior. But when tests use mocks, those mocks can accidentally ship to production. Passing tests don't prove production readiness.
What Jest validates
- Code behavior against test expectations
- Function outputs with given inputs
- Component rendering and interactions
- Async operations and promises
- Error handling paths
What Jest misses
- Mock libraries included in production builds
- Test fixtures in deployed artifacts
- Fallback clients triggered by missing config
- Placeholder handlers in production routes
- Real service wiring validation
The gap
Jest tests against mocks. If those mocks are accidentally included in production, the tests still pass—but production serves fake data. Tests validate behavior, not reality.
The solution: Add a reality gate
Complement Jest with a deploy gate that validates:
- Mock/stub imports excluded from production builds
- Test fixtures not in build artifacts
- Real service wiring verified
- Required env vars present
Practical example
# Jest tests (existing) npm test # Add reality gate (new) npx guardrail mockproof npx guardrail gateResult
Jest ensures code works correctly. The reality gate ensures code uses real services. Together they prevent both broken logic and fake data.
Some teams use guardrail to detect this automatically in CI.