From 018c6337ff9747b8a59422d4502bdb0f6d9b695f Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 3 Jul 2025 12:03:18 -0700 Subject: [PATCH] Mock IntersectionObserver in Jest setup --- src-ui/setup-jest.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src-ui/setup-jest.ts b/src-ui/setup-jest.ts index c24762313..c52c00647 100644 --- a/src-ui/setup-jest.ts +++ b/src-ui/setup-jest.ts @@ -121,6 +121,26 @@ if (!URL.revokeObjectURL) { } Object.defineProperty(window, 'ResizeObserver', { value: mock() }) +if (typeof IntersectionObserver === 'undefined') { + class MockIntersectionObserver { + constructor( + public callback: IntersectionObserverCallback, + public options?: IntersectionObserverInit + ) {} + + observe = jest.fn() + unobserve = jest.fn() + disconnect = jest.fn() + takeRecords = jest.fn() + } + + Object.defineProperty(window, 'IntersectionObserver', { + writable: true, + configurable: true, + value: MockIntersectionObserver, + }) +} + HTMLCanvasElement.prototype.getContext = < typeof HTMLCanvasElement.prototype.getContext >jest.fn()