Skip to content

Commit

Permalink
Test that timeout error is not erroneously emitted using promise inte…
Browse files Browse the repository at this point in the history
…rface (#529)

Relates to #528
  • Loading branch information
jstewmon authored and sindresorhus committed Jul 18, 2018
1 parent 13bb0fa commit 75fd8d3
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion test/timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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();
});

0 comments on commit 75fd8d3

Please sign in to comment.