Skip to content

Commit db78ec9

Browse files
authored
Merge branch 'master' into transform
2 parents b737b59 + 28aa074 commit db78ec9

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
"eslint": "^6.8.0",
3131
"eslint-config-developit": "^1.1.1",
3232
"file-loader": "^5.0.2",
33+
"isomorphic-fetch": "^2.2.1",
3334
"jest": "^24.9.0",
3435
"karmatic": "^1.4.0",
3536
"microbundle": "^0.11.0",
3637
"sinon": "^8.0.4",
3738
"webpack": "^4.41.5"
3839
}
39-
}
40+
}

src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ export default (function create(defaults) {
155155
}
156156
}
157157
}
158-
158+
159+
const fetchFunc = options.fetch || fetch;
159160
const customHeaders = {};
160161

161162
if (data && typeof data === 'object') {
@@ -181,7 +182,7 @@ export default (function create(defaults) {
181182
const response = {};
182183
response.config = config;
183184

184-
return fetch(url, {
185+
return fetchFunc(url, {
185186
method: options.method,
186187
body: data,
187188
headers: deepMerge(options.headers, customHeaders, true)

test/index.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import axios from '../src/index.js';
1616
import textExample from 'file-loader!./fixtures/example.txt';
1717
import jsonExample from 'file-loader!./fixtures/example.json.txt';
18+
import fetch from 'isomorphic-fetch';
1819

1920
describe('redaxios', () => {
2021
it('smoke test', () => {
@@ -82,4 +83,13 @@ describe('redaxios', () => {
8283
window.fetch = oldFetch;
8384
}
8485
});
86+
87+
it('should accept a custom fetch implementation', async () => {
88+
const req = axios.get(jsonExample, { fetch });
89+
expect(req).toBeInstanceOf(Promise);
90+
const res = await req;
91+
expect(res).toBeInstanceOf(Object);
92+
expect(res.status).toEqual(200);
93+
expect(JSON.parse(res.data)).toEqual({ hello: 'world' });
94+
});
8595
});

0 commit comments

Comments
 (0)