From 6762761eac68fee30e8a6ba619168a362c5f90dd Mon Sep 17 00:00:00 2001 From: Kyle Welch Date: Thu, 6 Dec 2018 23:13:26 -0600 Subject: [PATCH] Add GET as default request method --- src/__tests__/request.spec.ts | 13 +++++++++++++ src/request.ts | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/__tests__/request.spec.ts b/src/__tests__/request.spec.ts index 4ddfca8..a078f22 100644 --- a/src/__tests__/request.spec.ts +++ b/src/__tests__/request.spec.ts @@ -58,6 +58,19 @@ describe('request', () => { ); }); + it('calls should not send "application/json", if method is not passed', async () => { + await request(TEST_URL); + + expect(getMockFetch()).toHaveBeenCalledTimes(1); + expect(getMockFetch()).toHaveBeenCalledWith( + TEST_URL, + expect.objectContaining({ + credentials: 'same-origin', + headers: {}, + }) + ); + }); + it('calls fetch and respects overrides in options', async () => { await request(TEST_URL, {credentials: 'omit'}); diff --git a/src/request.ts b/src/request.ts index 4141a4b..4b908be 100644 --- a/src/request.ts +++ b/src/request.ts @@ -37,7 +37,7 @@ const _tryParseJSON = (res: Response): Promise => { */ export const _fetchJSON = ( url: string, - {headers, method, mode, ...options}: RequestInit = {} + {headers = {}, method = 'GET', mode, ...options}: RequestInit = {} ): Promise<{}> => { let fetchHeaders = headers as HeadersInit;