title: Testing FormData submitted to fetch using jest
body: <p>I'm using Jest to test calling an API in my React app.</p>
  
  <p>The code I'm testing is:</p>
  
  <pre><code>const createItem = (data) =&gt; {
    let formData = buildForm(data);
  
    return fetch(URL, {
      method: 'POST',
      body: formData
    });
  };
  </code></pre>
  
  <p>I want to confirm that the <code>buildForm</code> function correctly converts the <code>data</code> to a <code>FormData</code> object.</p>
  
  <p>My test looks like this:</p>
  
  <pre><code>it('creates item using api', () =&gt; {
    let data = {name: 'test name'};
    return createItem(data)
      .then(() =&gt; {
        let expForm = new FormData();
        expForm.append('name', data.name);
  
        expect(global.fetch).toHaveBeenCalledWith(URL, {
          method: 'POST',
          body: expForm
        });
      });
  });
  </code></pre>
  
  <p>The problem is, this test passes regardless what fields I append to <code>expForm</code> in my test. It seems like <code>toHaveBeenCalledWith</code> doesn't actually compare the values of <code>body</code> and just checks that it is a <code>FormData</code> object.</p>
  
  <p>How can I test the values passed into the <code>body</code> FormData object?</p>