title: React Native - mocking FormData in unit tests
body: <p>I'm having issues testing my thunks, as many of my API calls are using FormData, and I can't seem to figure out how to mock this in tests. I'm using Jest. </p>
  
  <p>My setup file looks like this: </p>
  
  <pre><code>import 'isomorphic-fetch';
  
  // Mocking the global.fetch included in React Native
  global.fetch = jest.fn();
  
  // Helper to mock a success response (only once)
  fetch.mockResponseSuccess = body =&gt; {
    fetch.mockImplementationOnce(() =&gt;
      Promise.resolve({ json: () =&gt; Promise.resolve(JSON.parse(body)) })
    );
  };
  
  // Helper to mock a failure response (only once)
  fetch.mockResponseFailure = error =&gt; {
    fetch.mockImplementationOnce(() =&gt; Promise.reject(error));
  };
  </code></pre>
  
  <p>However, I get the following error on all tests that require FormData: </p>
  
  <pre><code>ReferenceError: FormData is not defined
  </code></pre>
  
  <p>I've tried importing the FormData file from <code>react-native-mock</code>, under <code>src/Libraries/Network/FormData</code>, but it didn't work. </p>
  
  <p>So I was wondering if anyone has had any luck doing this? </p>
  
  <p>In general, I'm having a hard time figuring out the best way to mock <code>fetch</code> requests in React Native, so any advice here would be nice. I've tried the <code>jest-fetch-mock</code> lib (and opened an issue about FormData), tried setting up with <code>nock</code> (no luck), and this plain Jest implementation, but nothing feels right yet. </p>