// Learn more: https://github.com/testing-library/jest-dom import '@testing-library/jest-dom' // Node polyfills for libs that expect TextEncoder/TextDecoder even in jsdom. // (e.g. jspdf → fast-png → iobuffer) try { // eslint-disable-next-line @typescript-eslint/no-var-requires const util = require('node:util'); if (!global.TextEncoder) global.TextEncoder = util.TextEncoder; if (!global.TextDecoder) global.TextDecoder = util.TextDecoder; } catch { // ignore } // Mock Next.js router jest.mock('next/navigation', () => ({ useRouter: () => ({ push: jest.fn(), replace: jest.fn(), prefetch: jest.fn(), back: jest.fn(), }), usePathname: () => '/dashboard', useSearchParams: () => new URLSearchParams(), })) // Mock window.location if (typeof window !== 'undefined') { delete window.location; window.location = { origin: 'http://localhost:3000', href: 'http://localhost:3000/dashboard', reload: jest.fn(), }; } // Mock localStorage const localStorageMock = { getItem: jest.fn(), setItem: jest.fn(), removeItem: jest.fn(), clear: jest.fn(), } global.localStorage = localStorageMock // Mock sessionStorage const sessionStorageMock = { getItem: jest.fn(), setItem: jest.fn(), removeItem: jest.fn(), clear: jest.fn(), } global.sessionStorage = sessionStorageMock // Suppress console errors in tests unless needed global.console = { ...console, error: jest.fn(), warn: jest.fn(), }