Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fa64369

Browse files
authoredDec 27, 2019
Merge pull request #121 from suppermancool/code-30110655
Code 30110655
2 parents 43c61a5 + c618515 commit fa64369

File tree

13 files changed

+2554
-3291
lines changed

13 files changed

+2554
-3291
lines changed
 

‎__tests__/actions/auth.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,22 @@ jest.mock('isomorphic-fetch', () => jest.fn(url => Promise.resolve({
1515
},
1616
})));
1717

18-
const fetch = require('isomorphic-fetch');
18+
jest.mock('cross-fetch', () => jest.fn(url => Promise.resolve({
19+
json: () => {
20+
let content;
21+
switch (url) {
22+
case MOCK_GROUPS_REQ_URL: content = ['Group1', 'Group2']; break;
23+
case MOCK_PROFILE_REQ_URL: content = { userId: 12345 }; break;
24+
default: throw new Error('Unexpected URL!');
25+
}
26+
return {
27+
result: { content, status: 200 },
28+
};
29+
},
30+
})));
31+
32+
// const fetch = require('isomorphic-fetch');
33+
const crossfetch = require('cross-fetch');
1934
const { actions } = require('../../src');
2035

2136
describe('fetch with success response', () => {
@@ -25,13 +40,13 @@ describe('fetch with success response', () => {
2540
const action = actions.auth.loadProfile('token');
2641
expect(action.type).toBe('AUTH/LOAD_PROFILE');
2742
return action.payload.then((res) => {
28-
expect(fetch).toHaveBeenCalledWith(MOCK_PROFILE_REQ_URL, {
43+
expect(crossfetch).toHaveBeenCalledWith(MOCK_PROFILE_REQ_URL, {
2944
headers: {
3045
Authorization: 'Bearer token',
3146
'Content-Type': 'application/json',
3247
},
3348
});
34-
expect(fetch).toHaveBeenCalledWith(MOCK_GROUPS_REQ_URL, {
49+
expect(crossfetch).toHaveBeenCalledWith(MOCK_GROUPS_REQ_URL, {
3550
headers: {
3651
Authorization: 'Bearer token',
3752
'Content-Type': 'application/json',

‎__tests__/services/api.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ jest.mock(
44
() => jest.fn((url, ops) => Promise.resolve({ url, ops })),
55
);
66

7+
jest.mock(
8+
'cross-fetch',
9+
() => jest.fn((url, ops) => Promise.resolve({ url, ops })),
10+
);
11+
712
const { config } = require('topcoder-react-utils');
813
const { getApi } = require('../../src/services/api');
914

‎dist/dev/index.js

Lines changed: 68 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.