From 0c724e3590995aea29f90e8d8e9def9df6790f40 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 fbbb624db..de28ecb8b 100644 --- a/src-ui/setup-jest.ts +++ b/src-ui/setup-jest.ts @@ -119,6 +119,26 @@ Object.defineProperty(window, 'location', { value: { reload: jest.fn() }, }) +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()