diff --git a/source/index.ts b/source/index.ts index 1dbf44679..21882cdeb 100644 --- a/source/index.ts +++ b/source/index.ts @@ -69,6 +69,10 @@ const defaults: Defaults = { context: {}, _pagination: { transform: (response: Response) => { + if (response.request.options.responseType === 'json') { + return response.body; + } + return JSON.parse(response.body as string); }, paginate: response => { diff --git a/test/pagination.ts b/test/pagination.ts index 031294dbe..5d457e8f3 100644 --- a/test/pagination.ts +++ b/test/pagination.ts @@ -47,6 +47,16 @@ test('retrieves all elements', withServer, async (t, server, got) => { t.deepEqual(result, [1, 2]); }); +test('retrieves all elements with JSON responseType', withServer, async (t, server, got) => { + attachHandler(server, 2); + + const result = await got.extend({ + responseType: 'json' + }).paginate.all(''); + + t.deepEqual(result, [1, 2]); +}); + test('points to defaults when extending Got without custom `_pagination`', withServer, async (t, server, got) => { attachHandler(server, 2);