Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(request): Set GET as default request method #50

Merged
merged 1 commit into from
Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/__tests__/request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'});

Expand Down
2 changes: 1 addition & 1 deletion src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const _tryParseJSON = (res: Response): Promise<any> => {
*/
export const _fetchJSON = (
url: string,
{headers, method, mode, ...options}: RequestInit = {}
{headers = {}, method = 'GET', mode, ...options}: RequestInit = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to accomplish this would be to update the if below to match how we do it internally.

if (method && method !== 'GET') {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should go with the other way. Otherwise a lot of internal code would break.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internally, we also default it, but we do it later in this function. I would imagine the internal function was written pre-es6 defaults

): Promise<{}> => {
let fetchHeaders = headers as HeadersInit;

Expand Down