Mock libraries are imported only in test files
Why it matters
Mock libraries like msw, nock, and sinon are designed to intercept network calls and fabricate responses. When they leak into production source files, real API requests get hijacked by test doubles — users see stubbed data, webhooks never reach their destinations, and payment flows silently return mock success responses. This also bloats production bundles with test-only code and can mask outages because the mock always returns 200 OK regardless of backend health.
Severity rationale
Medium because the breakage ranges from silent data corruption to full feature outage depending on which request the mock intercepts.
Remediation
Move each flagged mock import into the corresponding test file under tests/ or __tests__/, or into a test-only setup module. If the production file genuinely needs a stubbed response (feature flag, offline mode), use a real implementation behind an environment check instead of a mock library.
// tests/setup.ts — test-only, never imported from src/
import { setupServer } from 'msw/node'
export const server = setupServer()
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Test Reality Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
Taxons
History
- 2026-04-18·v1.0.0·Initial import from ai-slop-test-theater·automated