import "@testing-library/jest-dom/vitest"; import { afterEach, vi } from "vitest"; import { cleanup } from "@testing-library/react"; // @excalidraw/excalidraw bundles roughjs with a broken CJS path in its dev // build. Stub the whole package in tests — excalidraw is loaded lazily in // production and never needed in unit/integration tests. vi.mock("@excalidraw/excalidraw", () => ({ Excalidraw: () => null, exportToBlob: vi.fn(), exportToSvg: vi.fn(), serializeAsJSON: vi.fn(), loadLibraryFromBlob: vi.fn(), convertToExcalidrawElements: vi.fn(), })); // @/main.tsx mounts the React app on #root which does not exist in jsdom. // Any feature module that imports { queryClient } from "@/main.tsx" would // trigger the mount side-effect — stub it to avoid the crash. vi.mock("@/main.tsx", () => ({ queryClient: { getQueryData: vi.fn(), setQueryData: vi.fn(), invalidateQueries: vi.fn(), prefetchQuery: vi.fn(), fetchQuery: vi.fn(), clear: vi.fn(), }, })); afterEach(() => { cleanup(); }); // Stubs for browser APIs Mantine relies on but jsdom does not provide. if (typeof Element !== "undefined" && !Element.prototype.scrollIntoView) { Element.prototype.scrollIntoView = function () {}; } if (typeof window !== "undefined") { if (!window.matchMedia) { window.matchMedia = vi.fn().mockImplementation((query: string) => ({ matches: false, media: query, onchange: null, addEventListener: vi.fn(), removeEventListener: vi.fn(), addListener: vi.fn(), removeListener: vi.fn(), dispatchEvent: vi.fn(), })); } if (!(window as unknown as { ResizeObserver?: unknown }).ResizeObserver) { (window as unknown as { ResizeObserver: unknown }).ResizeObserver = class { observe() {} unobserve() {} disconnect() {} }; } }