Skip to content

Commit

Permalink
Test responseType set to undefined
Browse files Browse the repository at this point in the history
Fixes #1252
  • Loading branch information
szmarczak committed May 12, 2020
1 parent 9b04963 commit 0e8582f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions source/as-promise/core.ts
Expand Up @@ -57,6 +57,12 @@ export default class PromisableRequest extends Request {
assert.any([is.boolean, is.undefined], options.resolveBodyOnly);
assert.any([is.boolean, is.undefined], options.methodRewriting);
assert.any([is.boolean, is.undefined], options.isStream);
assert.any([is.string, is.undefined], options.responseType);

// `options.responseType`
if (options.responseType === undefined) {
options.responseType = 'text';
}

// `options.retry`
const {retry} = options;
Expand Down
1 change: 1 addition & 0 deletions source/core/index.ts
Expand Up @@ -624,6 +624,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
assert.any([is.boolean, is.undefined], options.http2);
assert.any([is.boolean, is.undefined], options.allowGetBody);
assert.any([is.boolean, is.undefined], options.rejectUnauthorized);
assert.any([is.string, is.undefined], options.localAddress);

// `options.method`
if (is.string(options.method)) {
Expand Down
6 changes: 6 additions & 0 deletions test/response-parse.ts
Expand Up @@ -44,6 +44,12 @@ test('Text response', withServer, async (t, server, got) => {
t.is((await got({responseType: 'text'})).body, jsonResponse);
});

test('Text response #2', withServer, async (t, server, got) => {
server.get('/', defaultHandler);

t.is((await got({responseType: undefined})).body, jsonResponse);
});

test('JSON response - promise.json()', withServer, async (t, server, got) => {
server.get('/', defaultHandler);

Expand Down

0 comments on commit 0e8582f

Please sign in to comment.