Skip to content

Commit

Permalink
fix: fetchJsonWithAuthToken missing options param (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: koo6666 <gujixian@xingfeiinc.com>
Co-authored-by: Bojan Mihelac <bmihelac@mihelac.org>
  • Loading branch information
bmihelac and koo6666 committed Jul 1, 2020
1 parent 60cc95d commit e51f17e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/tokenAuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ export function createOptionsFromToken() {
};
}

export function fetchJsonWithAuthToken(url: string) {
return fetchUtils.fetchJson(url, createOptionsFromToken());
export function fetchJsonWithAuthToken(url: string, options: object) {
console.log(options);
return fetchUtils.fetchJson(
url,
Object.assign(createOptionsFromToken(), options)
);
}

export default tokenAuthProvider;
10 changes: 10 additions & 0 deletions test/tokenAuthProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fetchMock from 'fetch-mock-jest';

import tokenAuthProvider, {
createOptionsFromToken,
fetchJsonWithAuthToken,
} from '../src/tokenAuthProvider';

fetchMock.config.overwriteRoutes = true;
Expand Down Expand Up @@ -96,3 +97,12 @@ describe('createOptionsFromToken', () => {
expect(createOptionsFromToken()).toEqual({});
});
});

describe('fetchJsonWithAuthToken', function() {
fetchMock.patch('/', 200);
test('with options', () => {
fetchJsonWithAuthToken('/', {
method: 'PATCH',
});
});
});

0 comments on commit e51f17e

Please sign in to comment.