Mock Data in Production: Why It Happens (and How to Stop It)
If mock data, fake APIs, or test responses reached production, your tooling failed silently. The fix is not "write more tests." The fix is a deploy gate that detects non-real code paths before shipping.
What "mock data in production" actually means
This usually shows up as:
- Users seeing placeholder content ("John Doe", "Lorem ipsum", demo prices)
- API responses that look valid but are not from real services
- Feature flags or dev-only branches accidentally enabled
- "Temporary" stubs that became permanent
Common examples
__mocks__folders shipped in build outputmsw/ mock service workers enabled in non-dev environments- Functions returning hardcoded objects that pass type-checks
- A "fake" service client used when env vars are missing
Why CI and linters miss this
Most pipelines verify syntax and tests, but not reality:
- Type-checking can't tell if a function returns fabricated data
- Tests can pass against stubs
- Mocks can be conditionally imported (only visible at runtime)
- Monorepos hide "dev-only" code in shared packages
CI typically answers: "Does it compile?"
Production needs: "Is it real?"
The prevention pattern: a MockProof gate
A MockProof gate scans for mock and fake-code signals before deploy:
- Import graph + file-path patterns (
__mocks__,fixtures,mock,fake,seed) - Known mocking libraries used outside dev/test
- Build artifact inspection (what is actually in the shipped output)
- Optional allowlists for legitimate fixtures in non-prod docs/examples
One-command check (example)
npx guardrail mockproofCI example
# fail the build if mock/fake code is detected npx guardrail gateWhat to do if you already shipped it
Stop the bleed
- Disable mock toggles / MSW in prod immediately
- Find the source (look for conditional imports, missing env vars, and fallback clients)
- Add the gate (make reality checks a required CI step)
Who this is for
- Teams shipping fast with AI-assisted coding
- Monorepos with shared "utils" packages
- Startups that can't afford silent production hallucinations
Next step
If you want production to stop accepting fake data as "valid," add a reality gate:
- MockProof: catches leftover mocks and fake responses
- Reality Mode: validates runtime boundaries and wiring