From 9ed0a39bcd55b13a31aad22164cba1a9afe7e194 Mon Sep 17 00:00:00 2001 From: Szymon Marczak <36894700+szmarczak@users.noreply.github.com> Date: Sun, 3 May 2020 19:51:25 +0200 Subject: [PATCH] Make `options.responseType` optional when using a template Fixes #1178 --- source/types.ts | 2 +- test/response-parse.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/source/types.ts b/source/types.ts index 22a7891c5..15c23d46d 100644 --- a/source/types.ts +++ b/source/types.ts @@ -42,7 +42,7 @@ export interface ExtendOptions extends Options { } export type OptionsOfTextResponseBody = Merge; -export type OptionsOfJSONResponseBody = Merge; +export type OptionsOfJSONResponseBody = Merge; export type OptionsOfBufferResponseBody = Merge; export type StrictOptions = Except; export type StreamOptions = Merge; diff --git a/test/response-parse.ts b/test/response-parse.ts index 420d4a7ce..b32f2ab5b 100644 --- a/test/response-parse.ts +++ b/test/response-parse.ts @@ -1,5 +1,6 @@ import test from 'ava'; import {Handler} from 'express'; +import getStream = require('get-stream'); import {HTTPError, ParseError} from '../source'; import withServer from './helpers/with-server'; @@ -222,3 +223,16 @@ test('shortcuts result properly when retrying in afterResponse', withServer, asy t.is(text, proper); t.is(buffer.compare(Buffer.from(proper)), 0); }); + +test('responseType is optional when using template', withServer, async (t, server, got) => { + const data = {hello: 'world'}; + + server.post('/', async (request, response) => { + response.end(await getStream(request)); + }); + + const jsonClient = got.extend({responseType: 'json'}); + const {body} = await jsonClient.post('', {json: data}); + + t.deepEqual(body, data); +});