/** * Shared spies for the mocked expo-router. * * The mock lives in each test file rather than in tests/setup.ts: a global mock * would also apply to tests/home-page/navigation.test.tsx, which needs the real * router (expo-router/testing-library). Any test file that renders a router * consumer and is not using the real router must add: * * jest.mock('expo-router', () => require('../mocks/router').expoRouterMock()) * * `clearMocks: true` in jest.config.js clears these between tests, but zustand * stores are not mocks - reset them explicitly where they matter. */ export const routerMock = { push: jest.fn(), replace: jest.fn(), back: jest.fn(), navigate: jest.fn(), } export function resetRouterMock() { routerMock.push.mockClear() routerMock.replace.mockClear() routerMock.back.mockClear() routerMock.navigate.mockClear() } /** Factory for jest.mock('expo-router', ...). */ export function expoRouterMock() { return { useRouter: () => routerMock, router: routerMock, useLocalSearchParams: () => ({}), useGlobalSearchParams: () => ({}), useFocusEffect: () => {}, Link: ({ children }: { children?: unknown }) => children ?? null, } }