import '@testing-library/jest-dom'; import { TextEncoder, TextDecoder } from 'util'; // Polyfills for Node.js environment global.TextEncoder = TextEncoder; global.TextDecoder = TextDecoder; // Mock NextResponse for API route testing jest.mock('next/server', () => ({ NextResponse: { json: jest.fn((data, options) => ({ data, status: options?.status || 200, json: async () => data, })), }, })); // Mock Next.js router jest.mock('next/navigation', () => ({ useRouter() { return { push: jest.fn(), replace: jest.fn(), prefetch: jest.fn(), back: jest.fn(), forward: jest.fn(), refresh: jest.fn(), }; }, useParams() { return {}; }, usePathname() { return ''; }, useSearchParams() { return new URLSearchParams(); }, })); // Mock window.confirm for delete operations global.confirm = jest.fn(() => true); // Mock console.error to avoid noise in tests const originalError = console.error; beforeAll(() => { console.error = (...args) => { if ( typeof args[0] === 'string' && args[0].includes('Warning: ReactDOM.render is no longer supported') ) { return; } originalError.call(console, ...args); }; }); afterAll(() => { console.error = originalError; }); // Mock fetch globally global.fetch = jest.fn(); // Reset all mocks between tests beforeEach(() => { jest.clearAllMocks(); });