JS - Testing code that uses an IntersectionObserver

前端 未结 6 1654
死守一世寂寞
死守一世寂寞 2020-12-18 17:57

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

6条回答
  •  再見小時候
    2020-12-18 18:57

    I had this problem with a setup based on vue-cli. I ended up using a mix of the answers I saw above:

       const mockIntersectionObserver = class {
        constructor() {}
        observe() {}
        unobserve() {}
        disconnect() {}
      };
    
      beforeEach(() => {
        window.IntersectionObserver = mockIntersectionObserver;
      });
    

提交回复
热议问题