How to ETIMEDOUT with nock and request library
<p>How to force ETIMEDOUT with <code>nock</code> (<a href="https://github.com/node-nock/nock" rel="nofollow">https://github.com/node-nock/nock</a>) and <code>request</code>?<br> I tried following, where <code>nock</code> will delay response for 8000 milliseconds while timeout for request will be set to 5000 milliseconds, so i would expect to see <code>ETIMEDOUT</code> but that is not the case. Code will return <code>then block should not execute:  Hello from Google!</code></p>

<p>mocha test/force-req-timeout.test.js --timeout=10000</p>

<pre><code>'use strict'

const expect = require('chai').expect
const nock = require('nock')
const rp = require('request-promise')

describe('force request timeout with nock', () =&gt; {
  it('should return ETIMEDOUT', (done) =&gt; {

    nock('http://www.google.com')
    .get('/')
    .delay(8000)
    .reply(200, 'Hello from Google!')

    rp({
      url: 'http://www.google.com',
      timeout: 5000
    })
    .then((data) =&gt; {
      console.log('then block should not execute: ', data)
    })
    .catch((err) =&gt; {
      expect(err.cause.code).to.equal('ETIMEDOUT')
      return done()
    })
  })
})
</code></pre>