import "@testing-library/jest-dom"; if (typeof global.ResizeObserver === "undefined") { class ResizeObserver { observe() {} unobserve() {} disconnect() {} } global.ResizeObserver = ResizeObserver as typeof global.ResizeObserver; } // Mock IntersectionObserver if not available in JSDOM if (typeof global.IntersectionObserver === "undefined") { class IntersectionObserver { root: Element | Document | null = null; rootMargin: string = ""; thresholds: ReadonlyArray = []; private callback: IntersectionObserverCallback; private elements: Set = new Set(); constructor( callback: IntersectionObserverCallback, options?: IntersectionObserverInit, ) { this.callback = callback; this.root = options?.root || null; this.rootMargin = options?.rootMargin || ""; const threshold = options?.threshold ?? 0; this.thresholds = Array.isArray(threshold) ? threshold : [threshold]; } observe(target: Element) { this.elements.add(target); setTimeout(() => { this.callback( [ { target, isIntersecting: true, intersectionRatio: 1, boundingClientRect: target.getBoundingClientRect(), intersectionRect: target.getBoundingClientRect(), rootBounds: this.root instanceof Element ? this.root.getBoundingClientRect() : null, time: Date.now(), } as IntersectionObserverEntry, ], this, ); }, 0); } unobserve(target: Element) { this.elements.delete(target); } disconnect() { this.elements.clear(); } takeRecords(): IntersectionObserverEntry[] { return []; } } global.IntersectionObserver = IntersectionObserver as typeof global.IntersectionObserver; } // Mock PointerEvent if not available in JSDOM if (typeof global.PointerEvent === "undefined") { class PointerEvent extends MouseEvent { pointerId: number; pointerType: string; isPrimary: boolean; constructor(type: string, params: PointerEventInit = {}) { super(type, params); this.pointerId = params.pointerId || 0; this.pointerType = params.pointerType || "mouse"; this.isPrimary = params.isPrimary || false; } } global.PointerEvent = PointerEvent as typeof global.PointerEvent; } // Mock window.matchMedia Object.defineProperty(window, "matchMedia", { writable: true, value: jest.fn().mockImplementation((query) => ({ matches: false, media: query, onchange: null, addListener: jest.fn(), removeListener: jest.fn(), addEventListener: jest.fn(), removeEventListener: jest.fn(), dispatchEvent: jest.fn(), })), }); // O React estável do Jest não exporta (só o canary do Next): aqui ele só repassa os filhos. // Testes que conferem as props dele trocam este dublê pelo seu (jest.mock("react")). const actualReact = jest.requireActual("react"); actualReact.ViewTransition ??= ({ children }: { children?: unknown }) => children;