title: How to test component's resize behaviour
body: <p>I'm using Jest as the testing framework. I'm trying to test a function inside the ResizeObserver callback.</p>
  
  <pre><code>import ResizeObserver from 'resize-observer-polyfill';
  
  const fn = jest.fn();
  const element = document.createElement('div');
  
  document.body.appendChild(element);
  new ResizeObserver(() =&gt; {
    fn();
  }).observe(element);
  </code></pre>
  
  <p>In my test, I tried to change the width and height of <code>element</code> using the style property to make the <code>ResizeObserver</code> to trigger</p>
  
  <pre><code>it('should call the fn function', () =&gt; {
    element.style.width = '100px';
    element.style.height = '200px';
  
    expect(fn).toHaveBeenCalledTimes(2);
  });
  </code></pre>
  
  <p>But didn't work. Here's the test error</p>
  
  <p><code>Expected mock function to have been called two times, but it was called zero times.</code></p>
  
  <p>What do I need to do to simulate the <code>ResizeObserver</code> callback? Please help.</p>
  
  <p><strong>Note:</strong> The code above is an only simplified version.</p>