@@ -102,6 +102,44 @@ describe('Path rewriting', () => {
102102
103103 expect ( rewriter ( rewriteFn ) ) . toBe ( '/123/789' ) ;
104104 } ) ;
105+
106+ // Same tests as the above three, but async
107+
108+ it ( 'is async and should return unmodified path' , ( ) => {
109+ const rewriteFn = async path => {
110+ const promise = new Promise ( ( resolve , reject ) => {
111+ resolve ( path ) ;
112+ } ) ;
113+ const changed = await promise ;
114+ return changed ;
115+ } ;
116+
117+ expect ( rewriter ( rewriteFn ) ) . resolves . toBe ( '/123/456' ) ;
118+ } ) ;
119+
120+ it ( 'is async and should return alternative path' , ( ) => {
121+ const rewriteFn = async path => {
122+ const promise = new Promise ( ( resolve , reject ) => {
123+ resolve ( '/foo/bar' ) ;
124+ } ) ;
125+ const changed = await promise ;
126+ return changed ;
127+ } ;
128+
129+ expect ( rewriter ( rewriteFn ) ) . resolves . toBe ( '/foo/bar' ) ;
130+ } ) ;
131+
132+ it ( 'is async and should return replaced path' , ( ) => {
133+ const rewriteFn = async path => {
134+ const promise = new Promise ( ( resolve , reject ) => {
135+ resolve ( path . replace ( '/456' , '/789' ) ) ;
136+ } ) ;
137+ const changed = await promise ;
138+ return changed ;
139+ } ;
140+
141+ expect ( rewriter ( rewriteFn ) ) . resolves . toBe ( '/123/789' ) ;
142+ } ) ;
105143 } ) ;
106144
107145 describe ( 'Invalid configuration' , ( ) => {
@@ -136,5 +174,10 @@ describe('Path rewriting', () => {
136174 // tslint:disable-next-line: no-empty
137175 expect ( badFn ( ( ) => { } ) ) . not . toThrowError ( Error ) ;
138176 } ) ;
177+
178+ it ( 'should not throw when async function config is provided' , ( ) => {
179+ // tslint:disable-next-line: no-empty
180+ expect ( badFn ( async ( ) => { } ) ) . not . toThrowError ( Error ) ;
181+ } ) ;
139182 } ) ;
140183} ) ;
0 commit comments