title: How do I unit test HTTP requests?
body: <p>As the title asks how do I test HTTP requests with Mocha and Chai?</p>
  
  <p>I've recently started learning unit testing and I'm still getting confused with certain aspects of testing. I can get by fine testing methods that return a value but I'm confused on how to test methods that make HTTP/IO requests.</p>
  
  <p>For example I have the following code:</p>
  
  <pre><code>module.exports = someRequest =&gt; new Promise((resolve, reject) =&gt; 
      http.get('http://google.com', resp =&gt; {
          if(resp.headers['content-type'] !== 200) {
              reject(new Error('Failed to connect to Google'));
          }
          resolve('Connected to Google');
      })
  );
  </code></pre>
  
  <p>I want to test 2 cases:</p>
  
  <ol>
  <li>The request to Google succeed</li>
  <li>The request to Google failed</li>
  </ol>
  
  <p>Do I have to mock these requests and if so what's the purpose of mocking a method that is intended to make a HTTP request?</p>