From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 3 Jul 2025 19:03:18 +0000 (-0700) Subject: Mock IntersectionObserver in Jest setup X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=129dbf675e38f4a39073be21e3d98f7d2dbececb;p=thirdparty%2Fpaperless-ngx.git Mock IntersectionObserver in Jest setup --- 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()