From 60d6edb63ffb7cb1e08f2abc7f1ce6e4ed4f3b9a Mon Sep 17 00:00:00 2001 From: Alessandro Pogliaghi Date: Wed, 29 Jul 2026 11:47:11 +0100 Subject: [PATCH] fix(ui): polyfill animation frames in tests Provide requestAnimationFrame and cancelAnimationFrame in the jsdom setup so delayed callbacks from browser animation libraries cannot fail after their originating test has completed. Generated-By: PostHog Code Task-Id: 751a37dc-0eb5-4201-9a10-e2c694aada61 --- packages/ui/src/test/setup.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/ui/src/test/setup.ts b/packages/ui/src/test/setup.ts index 85bcaaf988..2e27ecf82e 100644 --- a/packages/ui/src/test/setup.ts +++ b/packages/ui/src/test/setup.ts @@ -77,6 +77,15 @@ if (typeof globalThis.ResizeObserver === "undefined") { ResizeObserverStub as unknown as typeof ResizeObserver; } +// jsdom does not implement animation frames. Components backed by browser +// animation libraries can schedule a frame from a delayed callback, turning an +// otherwise passing test into an unhandled ReferenceError later in the suite. +if (typeof globalThis.requestAnimationFrame === "undefined") { + globalThis.requestAnimationFrame = (callback: FrameRequestCallback) => + setTimeout(() => callback(performance.now()), 0) as unknown as number; + globalThis.cancelAnimationFrame = (handle: number) => clearTimeout(handle); +} + // jsdom does not implement Element.getAnimations. With ResizeObserver stubbed // above, Base UI's ScrollAreaViewport now mounts fully and schedules a timer // that calls viewport.getAnimations() — which would otherwise throw an