]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Mock IntersectionObserver in Jest setup
authorshamoon <4887959+shamoon@users.noreply.github.com>
Thu, 3 Jul 2025 19:03:18 +0000 (12:03 -0700)
committershamoon <4887959+shamoon@users.noreply.github.com>
Sat, 2 Aug 2025 12:22:55 +0000 (08:22 -0400)
src-ui/setup-jest.ts

index c2476231351a3368ea6d285169a23710fa08cfc1..c52c00647ad46eabf5c1a84b94ca601dccdb509b 100644 (file)
@@ -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()