title: How to test the args passed into document.body.appendChild with jest
body: <p>I have a function that creates a script element and adds it to the body. It looks a bit like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>const s = document.createElement('script');
  s.type = 'text/javascript';
  s.src = 'https://myscript';
  s.id = 'abc';
  
  document.body.appendChild(s);
  </code></pre>
  
  <p>I'm using testing using jest and am spying on the <code>appendChild</code> function to assert that the parameters passed in are what I expect. What I have looks like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>jest.spyOn(document.body, 'appendChild');
  
  doFunction();
  
  expect(document.body.appendChild).toBeCalledWith(
    '&lt;script id="abc" src="https://myscript" type="text/javascript" /&gt;',
  );
  </code></pre>
  
  <p>Despite the strings matching, the argument that gets passed into <code>appendChild</code> isn't a string, but an object. </p>
  
  <pre><code>typeof document.body.appendChild.mock.child[0][0] // object
  </code></pre>
  
  <p>I've also tried asserting against an object (<code>{ type: '...' }</code> with no luck. What other options are there with jest to test this bit of code?</p>