title: Testing MutationObserver with Jest
body: <p>I wrote a script with the main purpose of adding new elements to some table's cells.</p>
  
  <p>The test is done with something like that:</p>
  
  <pre><code>document.body.innerHTML = `
  &lt;body&gt;
      &lt;div id="${containerID}"&gt;
          &lt;table&gt;
              &lt;tr id="meta-1"&gt;&lt;td&gt; &lt;/td&gt;&lt;/tr&gt;
              &lt;tr id="meta-2"&gt;&lt;td&gt; &lt;/td&gt;&lt;/tr&gt;
              &lt;tr id="meta-3"&gt;&lt;td&gt; &lt;/td&gt;&lt;/tr&gt;
              &lt;tr id="no-meta-1"&gt;&lt;td&gt; &lt;/td&gt;&lt;/tr&gt;
          &lt;/table&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  `;
  
      const element = document.querySelector(`#${containerID}`);
  
      const subject = new WPMLCFInfoHelper(containerID);
      subject.addInfo();
  
      expect(mockWPMLCFInfoInit).toHaveBeenCalledTimes(3);
  </code></pre>
  
  <p><code>mockWPMLCFInfoInit</code>, when called, is what tells me that the element has been added to the cell.</p>
  
  <p>Part of the code is using MutationObserver to call again <code>mockWPMLCFInfoInit</code> when a new row is added to a table:</p>
  
  <pre><code>new MutationObserver((mutations) =&gt; {
      mutations.map((mutation) =&gt; {
          mutation.addedNodes &amp;&amp; Array.from(mutation.addedNodes).filter((node) =&gt; {
              console.log('New row added');
              return node.tagName.toLowerCase() === 'tr';
          }).map((element) =&gt; WPMLCFInfoHelper.addInfo(element))
      });
  }).observe(metasTable, {
      subtree:   true,
      childList: true
  });
  </code></pre>
  
  <p><code>WPMLCFInfoHelper.addInfo</code> is the real version of <code>mockWPMLCFInfoInit</code> (which is a mocked method, of course).</p>
  
  <p>From the above test, if add something like that...</p>
  
  <pre><code>const table = element.querySelector(`table`);
  var row = table.insertRow(0);
  </code></pre>
  
  <p><code>console.log('New row added');</code> never gets called. 
  To be sure, I've also tried adding the required cells in the new row.</p>
  
  <p>Of course, a manual test is telling me that the code works.</p>
  
  <p>Searching around, my understanding is that MutationObserver is not supported and <a href="https://github.com/facebook/jest/issues/580" rel="noreferrer">there is no plan to support it</a>.</p>
  
  <p>Fair enough, but in this case, how can I test this part of my code? Except manually, that is :)</p>