I have a (rather poorly written) javascript component in my application that handles infinite scroll pagination, and i\'m trying to rewrite it to use the IntersectionO
Had a similar stack issue as @Kevin Brotcke, except using their solution resulted in a further TypeScript error:
Function expression, which lacks return-type annotation, implicitly has an 'any' return type.
Here's a tweaked solution that worked for me:
beforeEach(() => {
// IntersectionObserver isn't available in test environment
const mockIntersectionObserver = jest.fn()
mockIntersectionObserver.mockReturnValue({
observe: jest.fn().mockReturnValue(null),
unobserve: jest.fn().mockReturnValue(null),
disconnect: jest.fn().mockReturnValue(null)
})
window.IntersectionObserver = mockIntersectionObserver
})