Browse Source

Add test to ensure that HTTP request errors are catched (#384)

no-retry
Patrick Poulain 7 years ago
committed by Sindre Sorhus
parent
commit
92ed73ad7f
  1. 1
      package.json
  2. 12
      test/error.js

1
package.json

@ -76,6 +76,7 @@
"get-port": "^3.0.0",
"nyc": "^11.0.2",
"pem": "^1.4.4",
"sinon": "^4.0.0",
"slow-stream": "0.0.4",
"tempfile": "^2.0.0",
"tempy": "^0.1.0",

12
test/error.js

@ -1,4 +1,6 @@
import http from 'http';
import test from 'ava';
import sinon from 'sinon';
import got from '..';
import {createServer} from './helpers/server';
@ -43,6 +45,16 @@ test('options.body error message', async t => {
t.regex(err.message, /options\.body must be a ReadableStream, string, Buffer or plain Object/);
});
test.serial('http.request error', async t => {
const stub = sinon.stub(http, 'request').callsFake(() => {
throw new TypeError('The header content contains invalid characters');
});
const err = await t.throws(got(s.url));
t.truthy(err instanceof TypeError);
t.regex(err.message, /The header content contains invalid characters/);
stub.restore();
});
test.after('cleanup', async () => {
await s.close();
});

Loading…
Cancel
Save