Mock
next/navigation with jest.mock and return a fake routerMock next/navigation with jest.mock and return a fake router. The App Router context only exists inside a running Next.js app, so unit tests mock the hooks. The tempting next/router option is wrong. next/router is the Pages Router API, and it doesn't work in App Router components. Switching to the node environment is wrong because it removes the DOM the test needs.
Read more