@@ -244,6 +244,28 @@ describe('axios-dev-proxy tests', () => {
244244 expect ( response . data ) . toEqual ( { data : 2 , xpto : 2 } ) ;
245245 expect ( response . status ) . toEqual ( 200 ) ;
246246 } ) ;
247+
248+ it ( 'should change original response with promise' , async ( ) => {
249+ server . get ( '/' ) . reply ( 200 , { data : 1 , xpto : 2 } ) ;
250+
251+ proxy . onGet ( '/' ) . changeResponseDataOnce < {
252+ data : number ;
253+ xpto : number ;
254+ } > (
255+ data =>
256+ new Promise ( resolve => {
257+ resolve ( {
258+ ...data ,
259+ data : 2 ,
260+ } ) ;
261+ } ) ,
262+ ) ;
263+
264+ const response = await api . get ( '/' ) ;
265+
266+ expect ( response . data ) . toEqual ( { data : 2 , xpto : 2 } ) ;
267+ expect ( response . status ) . toEqual ( 200 ) ;
268+ } ) ;
247269 } ) ;
248270
249271 describe ( 'always GET configs' , ( ) => {
@@ -448,5 +470,24 @@ describe('axios-dev-proxy tests', () => {
448470 expect ( server . pendingMocks ( ) ) . toHaveLength ( 1 ) ;
449471 expect ( server2 . pendingMocks ( ) ) . toHaveLength ( 1 ) ;
450472 } ) ;
473+
474+ it ( 'should change the request config once with a promise' , async ( ) => {
475+ const server2 = nock ( 'https://api-2.com.br' ) ;
476+ server2 . get ( '/config' ) . reply ( 200 , { data : 2 } ) ;
477+ server . get ( '/config' ) . reply ( 200 , { data : 1 } ) ;
478+ proxy . onGet ( '/config' ) . changeRequestOnce (
479+ async config =>
480+ new Promise ( resolve => {
481+ config . baseURL = 'https://api-2.com.br' ;
482+ resolve ( config ) ;
483+ } ) ,
484+ ) ;
485+
486+ await api . get ( '/config' ) ;
487+ await api . get ( '/config' ) ;
488+
489+ expect ( server . isDone ( ) ) . toBe ( true ) ;
490+ expect ( server2 . isDone ( ) ) . toBe ( true ) ;
491+ } ) ;
451492 } ) ;
452493} ) ;
0 commit comments