-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
33 lines (29 loc) · 1.18 KB
/
Copy pathvitest.setup.ts
File metadata and controls
33 lines (29 loc) · 1.18 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
// jsdom does not implement ResizeObserver, but the core DimensionManager
// constructs one when the table mounts and relies on its *initial* callback to
// read the container width and trigger the first render.
class ResizeObserverStub {
private callback: ResizeObserverCallback;
constructor(callback: ResizeObserverCallback) {
this.callback = callback;
}
observe(): void {
queueMicrotask(() => this.callback([], this as unknown as ResizeObserver));
}
unobserve(): void {}
disconnect(): void {}
}
globalThis.ResizeObserver = ResizeObserverStub as unknown as typeof ResizeObserver;
if (typeof globalThis.requestAnimationFrame !== "function") {
globalThis.requestAnimationFrame = ((cb: FrameRequestCallback) =>
setTimeout(() => cb(performance.now()), 0) as unknown as number) as typeof requestAnimationFrame;
globalThis.cancelAnimationFrame = ((id: number) =>
clearTimeout(id as unknown as ReturnType<typeof setTimeout>)) as typeof cancelAnimationFrame;
}
Object.defineProperty(HTMLElement.prototype, "clientWidth", {
configurable: true,
get() {
return 800;
},
});
// Keep this file a module so `ResizeObserverStub` is not a global across packages.
export {};