-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
61 lines (56 loc) · 1.66 KB
/
vitest.setup.ts
File metadata and controls
61 lines (56 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import "@testing-library/jest-dom/vitest";
import { afterEach, vi } from "vitest";
import { cleanup } from "@testing-library/react";
if (typeof window !== "undefined") {
class PointerEventPolyfill extends MouseEvent {
pointerId: number;
width: number;
height: number;
pressure: number;
tiltX: number;
tiltY: number;
pointerType: string;
isPrimary: boolean;
constructor(type: string, props: PointerEventInit = {}) {
super(type, props);
this.pointerId = props.pointerId ?? 0;
this.width = props.width ?? 0;
this.height = props.height ?? 0;
this.pressure = props.pressure ?? 0;
this.tiltX = props.tiltX ?? 0;
this.tiltY = props.tiltY ?? 0;
this.pointerType = props.pointerType ?? "mouse";
this.isPrimary = props.isPrimary ?? true;
Object.defineProperty(this, "__loopautomaInit", {
configurable: true,
enumerable: false,
value: { ...props },
});
}
}
Object.defineProperty(window, "PointerEvent", {
configurable: true,
writable: true,
value: PointerEventPolyfill,
});
// Mock setPointerCapture and releasePointerCapture for jsdom
if (typeof Element !== "undefined") {
Element.prototype.setPointerCapture = Element.prototype.setPointerCapture || function() {};
Element.prototype.releasePointerCapture = Element.prototype.releasePointerCapture || function() {};
}
}
afterEach(() => {
cleanup();
});
vi.mock("@tauri-apps/api/event", () => {
return {
listen: async (_name: string, _cb: any) => {
return () => {};
},
};
});
vi.mock("@tauri-apps/api/core", () => {
return {
invoke: vi.fn(async () => ({})),
};
});