Skip to content

Commit c31366b

Browse files
authoredSep 20, 2020
Add a test for #1438 (#1469)
1 parent 5d62958 commit c31366b

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed
 

‎test/promise.ts

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import {ReadStream} from 'fs';
12
import {ClientRequest, IncomingMessage} from 'http';
23
import test from 'ava';
3-
import {Response} from '../source';
4+
import {Response, CancelError} from '../source';
45
import withServer from './helpers/with-server';
56

67
test('emits request event as promise', withServer, async (t, server, got) => {
@@ -50,3 +51,31 @@ test('no unhandled `The server aborted pending request` rejection', withServer,
5051

5152
await t.throwsAsync(got(''));
5253
});
54+
55+
test('promise.json() can be called before a file stream body is open', withServer, async (t, server, got) => {
56+
server.post('/', (request, response) => {
57+
request.resume();
58+
request.once('end', () => {
59+
response.end('""');
60+
});
61+
});
62+
63+
// @ts-expect-error @types/node has wrong types.
64+
const body = new ReadStream('', {
65+
fs: {
66+
open: () => {},
67+
read: () => {},
68+
close: () => {}
69+
}
70+
});
71+
72+
const promise = got({body});
73+
const checks = [
74+
t.throwsAsync(promise, {instanceOf: CancelError}),
75+
t.throwsAsync(promise.json(), {instanceOf: CancelError})
76+
];
77+
78+
promise.cancel();
79+
80+
await Promise.all(checks);
81+
});

0 commit comments

Comments
 (0)
Please sign in to comment.