@@ -89,14 +89,15 @@ describe('safeExecuteInTheMiddle', function () {
8989} ) ;
9090
9191describe ( 'safeExecuteInTheMiddleAsync' , function ( ) {
92- it ( 'should not throw error' , function ( ) {
92+ it ( 'should not throw error' , function ( done ) {
9393 safeExecuteInTheMiddleAsync (
9494 async ( ) => {
95- await setTimeout ( ( ) => { } , 1 ) ;
95+ await new Promise ( res => setTimeout ( res , 1 ) ) ;
9696 return 'foo' ;
9797 } ,
9898 err => {
9999 assert . deepStrictEqual ( err , undefined ) ;
100+ done ( ) ;
100101 } ,
101102 true
102103 ) ;
@@ -106,7 +107,7 @@ describe('safeExecuteInTheMiddleAsync', function () {
106107 try {
107108 await safeExecuteInTheMiddleAsync (
108109 async ( ) => {
109- await setTimeout ( ( ) => { } , 1 ) ;
110+ await new Promise ( res => setTimeout ( res , 1 ) ) ;
110111 throw error ;
111112 } ,
112113 err => {
@@ -120,7 +121,7 @@ describe('safeExecuteInTheMiddleAsync', function () {
120121 it ( 'should return result' , async function ( ) {
121122 const result = await safeExecuteInTheMiddleAsync (
122123 async ( ) => {
123- await setTimeout ( ( ) => { } , 1 ) ;
124+ await new Promise ( res => setTimeout ( res , 1 ) ) ;
124125 return 1 ;
125126 } ,
126127 ( err , result ) => {
@@ -130,4 +131,17 @@ describe('safeExecuteInTheMiddleAsync', function () {
130131 ) ;
131132 assert . deepStrictEqual ( result , 1 ) ;
132133 } ) ;
134+ it ( 'should wait for the error' , async function ( ) {
135+ const result = await Promise . race ( [
136+ safeExecuteInTheMiddleAsync (
137+ ( ) => 1 ,
138+ async ( ) => {
139+ await new Promise ( res => setTimeout ( res , 100 ) ) ;
140+ }
141+ ) ,
142+ new Promise ( res => setTimeout ( ( ) => res ( 'waited' ) , 10 ) ) ,
143+ ] ) ;
144+
145+ assert . deepStrictEqual ( result , 'waited' ) ;
146+ } ) ;
133147} ) ;
0 commit comments