// jest-dom adds custom jest matchers for asserting on DOM nodes. // allows you to do things like: // expect(element).toHaveTextContent(/react/i) // learn more: https://github.com/testing-library/jest-dom import '@testing-library/jest-dom'; // Mock IntersectionObserver global.IntersectionObserver = class IntersectionObserver { constructor() {} disconnect() {} observe() {} unobserve() {} }; // Mock ResizeObserver global.ResizeObserver = class ResizeObserver { constructor() {} disconnect() {} observe() {} unobserve() {} }; // Mock window.matchMedia (only if window exists) if (typeof window !== 'undefined') { Object.defineProperty(window, 'matchMedia', { writable: true, value: jest.fn().mockImplementation(query => ({ matches: false, media: query, onchange: null, addListener: jest.fn(), // deprecated removeListener: jest.fn(), // deprecated addEventListener: jest.fn(), removeEventListener: jest.fn(), dispatchEvent: jest.fn(), })), }); } // Mock WebSocket global.WebSocket = class WebSocket { readyState: number; url: string; onopen: ((event: Event) => void) | null = null; onmessage: ((event: MessageEvent) => void) | null = null; onerror: ((event: Event) => void) | null = null; onclose: ((event: CloseEvent) => void) | null = null; constructor(url: string) { this.url = url; this.readyState = 0; // CONNECTING } send(data: string | ArrayBufferLike | Blob | ArrayBufferView) {} close(code?: number, reason?: string) {} addEventListener(type: string, listener: EventListener) {} removeEventListener(type: string, listener: EventListener) {} }; // Mock console methods to reduce noise in tests const originalError = console.error; const originalWarn = console.warn; beforeAll(() => { console.error = (...args: any[]) => { if ( typeof args[0] === 'string' && args[0].includes('Warning: ReactDOM.render is deprecated') ) { return; } originalError.call(console, ...args); }; console.warn = (...args: any[]) => { if ( typeof args[0] === 'string' && (args[0].includes('Warning: componentWillReceiveProps') || args[0].includes('Warning: componentWillUpdate')) ) { return; } originalWarn.call(console, ...args); }; }); afterAll(() => { console.error = originalError; console.warn = originalWarn; });