Testing code that uses an IntersectionObserver

None of the posted answered worked for me because of our configuration of TypeScript and React (tsx) we’re using. Here’s what finally worked: beforeEach(() => { // IntersectionObserver isn’t available in test environment const mockIntersectionObserver = jest.fn(); mockIntersectionObserver.mockReturnValue({ observe: () => null, unobserve: () => null, disconnect: () => null }); window.IntersectionObserver = mockIntersectionObserver; });

IntersectionObserver to create a lazy load Images with data-srcset and imagekit.io

I think your lazy loading may be creating these issues. If you check where your image requests originate you can see it’s from the loadImage function in universal.js that directly sets the src attribute of the image. Maybe you could try the native browser lazy loading and skip the intersection observer shenanigans: https://developer.mozilla.org/en-US/docs/Web/Performance/Lazy_loading