Elffuss BraidHub

kikocis/continue public

main · 1.6 KiBRawPermalink
1import "@testing-library/jest-dom";
2
3afterEach(() => {
4 vi.clearAllMocks();
5});
6
7afterAll(() => {
8 vi.resetAllMocks();
9});
10
11// Suppress uncaught ProseMirror errors in test environment
12window.addEventListener("error", (event) => {
13 if (
14 event.error?.message?.includes("getClientRects") ||
15 event.error?.message?.includes("prosemirror")
16 ) {
17 event.preventDefault();
18 return false;
19 }
20});
21
22window.addEventListener("unhandledrejection", (event) => {
23 if (
24 event.reason?.message?.includes("getClientRects") ||
25 event.reason?.message?.includes("prosemirror")
26 ) {
27 event.preventDefault();
28 return false;
29 }
30});
31
32// https://github.com/vitest-dev/vitest/issues/821
33Object.defineProperty(window, "matchMedia", {
34 writable: true,
35 value: vi.fn().mockImplementation((query) => ({
36 matches: false,
37 media: query,
38 onchange: null,
39 addListener: vi.fn(), // deprecated
40 removeListener: vi.fn(), // deprecated
41 addEventListener: vi.fn(),
42 removeEventListener: vi.fn(),
43 dispatchEvent: vi.fn(),
44 })),
45});
46
47// Mock getBoundingClientRect and getClientRects for ProseMirror
48Object.defineProperty(Element.prototype, "getClientRects", {
49 value: vi.fn(() => ({
50 length: 1,
51 0: { top: 0, bottom: 20, left: 0, right: 100, width: 100, height: 20 },
52 item: () => ({
53 top: 0,
54 bottom: 20,
55 left: 0,
56 right: 100,
57 width: 100,
58 height: 20,
59 }),
60 })),
61});
62
63Object.defineProperty(Element.prototype, "getBoundingClientRect", {
64 value: vi.fn(() => ({
65 top: 0,
66 bottom: 20,
67 left: 0,
68 right: 100,
69 width: 100,
70 height: 20,
71 })),
72});