title: How to test error in request with Nock?
body: <p>I want to test the error in a request return. I'm using nock in my tests, how can I force Nock to provoke an error? I want to achieve 100% test coverage and need to test err branch for that</p>
  
  <pre><code>request('/foo', function(err, res) {
    if(err) console.log('boom!');
  });
  </code></pre>
  
  <p>Never enter in the if err branch. Even if hit err is a valid response, my Nock line in test looks like this</p>
  
  <pre><code>nock('http://localhost:3000').get('/foo').reply(400);
  </code></pre>
  
  <p><strong>edit:</strong>
  thanks to some comments:</p>
  
  <ul>
  <li>I'm trying to mock an error in the request. From node manual:
  <a href="https://nodejs.org/api/http.html#http_http_request_options_callback" rel="noreferrer">https://nodejs.org/api/http.html#http_http_request_options_callback</a>
  <em>If any error is encountered during the request (be that with DNS resolution, TCP level errors, or actual HTTP parse errors) an 'error' event is emitted on the returned request object</em></li>
  <li>An error code (e.g. 4xx) doesn't define the err variable. I'm trying to mock exactly that, whatever error that defines the err variable and evaluates to true</li>
  </ul>