AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Jest Manual Mocks Stopped Working In Next.Js 13.2.4

Manual mocks in Jest are no longer resolved automatically after upgrading to Next.js 13.2.4; the next/jest preset appears to have broken Jest's default __mocks__ lookup.

highConfidence 75%Next.jsAffected V13.2.4Affected V13.2.5-Canary.32

Origin Analysis

Changes introduced in next/jest (likely PR #45815) altered module resolution, preventing Jest from automatically detecting __mocks__ directories for both node_modules and local modules.
1. Clone https://github.com/adam187/with-jest-app/tree/not-mocked 2. yarn install 3. yarn test Observe that the useTest hook is not mocked despite a __mocks__ folder being present at the root.

Fixing Code Block

Edge Case Audit

This workaround requires manually listing every mocked module, which becomes unmaintainable with many mocks. It only works for absolute module specifiers, not relative imports. Downgrading to Next.js 13.2.3 is a safer interim solution. To roll back this hotfix, remove the moduleNameMapper entry and restore the previous jest config.

Ecosystem Topology