Mock IntersectionObserver in Jest setup

This commit is contained in:
shamoon
2025-07-03 12:03:18 -07:00
parent 260b3dcf2a
commit c8b9952323

View File

@@ -121,6 +121,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()