Skip to content

Commit 75fd8d3

Browse files
jstewmonsindresorhus
authored andcommittedJul 18, 2018
Test that timeout error is not erroneously emitted using promise interface (#529)
Relates to #528
1 parent 13bb0fa commit 75fd8d3

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed
 

‎test/timeout.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ test('timeout with streams', async t => {
144144
await t.throws(pEvent(stream, 'response'), {code: 'ETIMEDOUT'});
145145
});
146146

147-
test('no error emitted when timeout is not breached', async t => {
147+
test('no error emitted when timeout is not breached (stream)', async t => {
148148
const stream = got.stream(s.url, {
149149
retry: 0,
150150
timeout: {
@@ -158,3 +158,20 @@ test('no error emitted when timeout is not breached', async t => {
158158
await delay(reqDelay * 3);
159159
t.pass();
160160
});
161+
162+
test('no error emitted when timeout is not breached (promise)', async t => {
163+
await got(s.url, {
164+
retry: 0,
165+
timeout: {
166+
request: reqDelay * 2
167+
}
168+
}).on('request', req => {
169+
// 'error' events are not emitted by the Promise interface, so attach
170+
// directly to the request object
171+
req.on('error', err => {
172+
t.fail(`error was emitted: ${err}`);
173+
});
174+
});
175+
await delay(reqDelay * 3);
176+
t.pass();
177+
});

0 commit comments

Comments
 (0)
Please sign in to comment.