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 @@ -142,7 +142,8 @@ export default (function create(defaults) {
142142 }
143143 }
144144 }
145-
145+
146+ const fetchFunc = options . fetch || fetch ;
146147 const customHeaders = { } ;
147148
148149 if ( data && typeof data === 'object' ) {
@@ -168,7 +169,7 @@ export default (function create(defaults) {
168169 const response = { } ;
169170 response . config = config ;
170171
171- return fetch ( url , {
172+ return fetchFunc ( url , {
172173 method : options . method ,
173174 body : data ,
174175 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' , ( ) => {
@@ -73,4 +74,13 @@ describe('redaxios', () => {
7374 window . fetch = oldFetch ;
7475 }
7576 } ) ;
77+
78+ it ( 'should accept a custom fetch implementation' , async ( ) => {
79+ const req = axios . get ( jsonExample , { fetch } ) ;
80+ expect ( req ) . toBeInstanceOf ( Promise ) ;
81+ const res = await req ;
82+ expect ( res ) . toBeInstanceOf ( Object ) ;
83+ expect ( res . status ) . toEqual ( 200 ) ;
84+ expect ( JSON . parse ( res . data ) ) . toEqual ( { hello : 'world' } ) ;
85+ } ) ;
7686} ) ;
You can’t perform that action at this time.
0 commit comments