AI Resource Pro / website / jest.setup.mjs
| 1 | // Mock environment variables |
| 2 | process.env.NEXT_PUBLIC_SITE_URL = 'http://localhost:3001'; |
| 3 | |
| 4 | // Mock Next.js router |
| 5 | jest.mock('next/navigation', () => ({ |
| 6 | useRouter: () => ({ |
| 7 | push: jest.fn(), |
| 8 | replace: jest.fn(), |
| 9 | prefetch: jest.fn(), |
| 10 | back: jest.fn(), |
| 11 | forward: jest.fn(), |
| 12 | refresh: jest.fn(), |
| 13 | pathname: '/', |
| 14 | query: {}, |
| 15 | }), |
| 16 | usePathname: () => '/', |
| 17 | useSearchParams: () => new URLSearchParams(), |
| 18 | })); |
| 19 | |
| 20 | // Mock Next.js server components |
| 21 | jest.mock('next/headers', () => ({ |
| 22 | cookies: () => ({ |
| 23 | get: jest.fn(() => ({ value: 'mock-cookie-value' })), |
| 24 | set: jest.fn(), |
| 25 | delete: jest.fn(), |
| 26 | }), |
| 27 | headers: () => new Map(), |
| 28 | })); |
| 29 | |
| 30 | // Mock Next.js Image component |
| 31 | jest.mock('next/image', () => ({ |
| 32 | __esModule: true, |
| 33 | default: function MockImage(props) { |
| 34 | // Return a mock object instead of JSX |
| 35 | return { |
| 36 | type: 'img', |
| 37 | props: { ...props, alt: props.alt || '' } |
| 38 | }; |
| 39 | }, |
| 40 | })); |
| 41 | |
| 42 | // Unauthenticated browser session unless a test opts into authentication. |
| 43 | jest.mock('@/lib/auth-client', () => ({ |
| 44 | authClient: { |
| 45 | useSession: jest.fn(() => ({ data: null, isPending: false })), |
| 46 | signIn: { social: jest.fn() }, |
| 47 | signOut: jest.fn(), |
| 48 | }, |
| 49 | })); |