/** * The trail has to be written by something, and it has to be written on every * route — not only the ones that happen to track an event. */ import { render } from '@testing-library/react'; const recordVisitedPath = jest.fn(); let pathname = '/schools/brentwood'; jest.mock('next/navigation', () => ({ usePathname: () => pathname })); jest.mock('@/lib/analytics', () => ({ recordVisitedPath: (p: string) => recordVisitedPath(p), })); // eslint-disable-next-line @typescript-eslint/no-var-requires const { RouteTrail } = require('@/components/RouteTrail'); describe('RouteTrail', () => { beforeEach(() => recordVisitedPath.mockClear()); it('records the page it is mounted on', () => { render(); expect(recordVisitedPath).toHaveBeenCalledWith('/schools/brentwood'); }); it('records each new route as the user moves through the app', () => { const { rerender } = render(); pathname = '/school/115429-brentwood-school'; rerender(); expect(recordVisitedPath).toHaveBeenLastCalledWith( '/school/115429-brentwood-school'); }); it('renders nothing, so it can sit anywhere in the layout', () => { const { container } = render(); expect(container).toBeEmptyDOMElement(); }); });