From 75fd8d3b5d5a5211d7c1781a917a6a5b985ab4b5 Mon Sep 17 00:00:00 2001 From: Jonathan Stewmon Date: Wed, 18 Jul 2018 14:29:35 -0500 Subject: [PATCH] Test that timeout error is not erroneously emitted using promise interface (#529) Relates to #528 --- test/timeout.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/timeout.js b/test/timeout.js index e17e04827..fb29a88dd 100644 --- a/test/timeout.js +++ b/test/timeout.js @@ -144,7 +144,7 @@ test('timeout with streams', async t => { await t.throws(pEvent(stream, 'response'), {code: 'ETIMEDOUT'}); }); -test('no error emitted when timeout is not breached', async t => { +test('no error emitted when timeout is not breached (stream)', async t => { const stream = got.stream(s.url, { retry: 0, timeout: { @@ -158,3 +158,20 @@ test('no error emitted when timeout is not breached', async t => { await delay(reqDelay * 3); t.pass(); }); + +test('no error emitted when timeout is not breached (promise)', async t => { + await got(s.url, { + retry: 0, + timeout: { + request: reqDelay * 2 + } + }).on('request', req => { + // 'error' events are not emitted by the Promise interface, so attach + // directly to the request object + req.on('error', err => { + t.fail(`error was emitted: ${err}`); + }); + }); + await delay(reqDelay * 3); + t.pass(); +});