2023-07-27 20:20:11 +02:00
|
|
|
// vitest.setup.ts
|
|
|
|
import "vitest-canvas-mock";
|
2020-02-11 23:19:43 +01:00
|
|
|
import "@testing-library/jest-dom";
|
2023-07-27 20:20:11 +02:00
|
|
|
import { vi } from "vitest";
|
2023-12-12 07:02:51 +01:00
|
|
|
import polyfill from "./packages/excalidraw/polyfill";
|
|
|
|
import { testPolyfills } from "./packages/excalidraw/tests/helpers/polyfills";
|
2023-10-28 21:29:28 +02:00
|
|
|
|
|
|
|
Object.assign(globalThis, testPolyfills);
|
2021-11-24 16:25:19 +01:00
|
|
|
|
2022-11-04 13:52:21 +01:00
|
|
|
require("fake-indexeddb/auto");
|
|
|
|
|
2022-08-11 16:46:25 +02:00
|
|
|
polyfill();
|
2021-11-24 16:25:19 +01:00
|
|
|
|
2024-04-08 16:46:24 +02:00
|
|
|
Object.defineProperty(window, "matchMedia", {
|
|
|
|
writable: true,
|
|
|
|
value: vi.fn().mockImplementation((query) => ({
|
|
|
|
matches: false,
|
|
|
|
media: query,
|
|
|
|
onchange: null,
|
|
|
|
addListener: vi.fn(), // deprecated
|
|
|
|
removeListener: vi.fn(), // deprecated
|
|
|
|
addEventListener: vi.fn(),
|
|
|
|
removeEventListener: vi.fn(),
|
|
|
|
dispatchEvent: vi.fn(),
|
|
|
|
})),
|
|
|
|
});
|
|
|
|
|
2023-07-27 20:20:11 +02:00
|
|
|
vi.mock("nanoid", () => {
|
2021-06-09 23:16:56 +02:00
|
|
|
return {
|
2023-07-27 20:20:11 +02:00
|
|
|
nanoid: vi.fn(() => "test-id"),
|
2021-06-09 23:16:56 +02:00
|
|
|
};
|
|
|
|
});
|
2020-02-11 23:19:43 +01:00
|
|
|
// ReactDOM is located inside index.tsx file
|
|
|
|
// as a result, we need a place for it to render into
|
|
|
|
const element = document.createElement("div");
|
|
|
|
element.id = "root";
|
|
|
|
document.body.appendChild(element);
|