Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Commit 92c2a07

Browse files
authored
fix(ui): polyfill animation frames in tests (#3930)
1 parent 211a86a commit 92c2a07

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎packages/ui/src/test/setup.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ if (typeof globalThis.ResizeObserver === "undefined") {
7777
ResizeObserverStub as unknown as typeof ResizeObserver;
7878
}
7979

80+
// jsdom does not implement animation frames. Components backed by browser
81+
// animation libraries can schedule a frame from a delayed callback, turning an
82+
// otherwise passing test into an unhandled ReferenceError later in the suite.
83+
if (typeof globalThis.requestAnimationFrame === "undefined") {
84+
globalThis.requestAnimationFrame = (callback: FrameRequestCallback) =>
85+
setTimeout(() => callback(performance.now()), 0) as unknown as number;
86+
globalThis.cancelAnimationFrame = (handle: number) => clearTimeout(handle);
87+
}
88+
8089
// jsdom does not implement Element.getAnimations. With ResizeObserver stubbed
8190
// above, Base UI's ScrollAreaViewport now mounts fully and schedules a timer
8291
// that calls viewport.getAnimations() — which would otherwise throw an

0 commit comments

Comments
 (0)