title: Write tests that rely on `IntersectionObserver` calls
body: <p>I'm trying to write a test that asserts something when element is in viewport.</p>
  
  <p>I'm using the <a href="https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver" rel="nofollow noreferrer"><code>IntersectionObserver</code></a> API, and it turns out that the calls to the observers is done when the browser can make them.</p>
  
  <p>So the question is, how should I approach such assertion?
  Should I just wait <em>some</em> time? How many milliseconds is enough?
  Is there an event to know when the browser finished calling observers?</p>
  
  <p>Currently I'm doing it like this:</p>
  
  <pre><code>// ... do whatever to make the code observe some elements
  document.scrollingElement.scrollTop = window.innerHeight;
  
  // Wait for observer to kick in (tried 1, 5, millis, 10 seems to work)
  await new Promise(resolve =&gt; setTimeout(resolve, 10));
  
  sinon.assert.calledWith(spy, dom.querySelector(selector));
  </code></pre>
  
  <p>This works, but I'm wondering if there's something better to wait for than just <em>some time</em>.</p>