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;