File tree Expand file tree Collapse file tree 3 files changed +15
-3
lines changed
Expand file tree Collapse file tree 3 files changed +15
-3
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff line change 1515import axios from '../src/index.js' ;
1616import textExample from 'file-loader!./fixtures/example.txt' ;
1717import jsonExample from 'file-loader!./fixtures/example.json.txt' ;
18+ import fetch from 'isomorphic-fetch' ;
1819
1920describe ( '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} ) ;
You can’t perform that action at this time.
0 commit comments