class MockAsync { executeSlowFunction ( complete ) { setTimeout ( ( ) => { complete ( `completed` ) ; } , 1000 ) ; } } describe ( "failing async tests" , ( ) => { xit ( "should wait for callback to complete" , ( ) => { let mockAsync = new MockAsync ( ) ; console . log ( `1. calling executeSlowFunction` ) ; let returnedValue ! ; mockAsync . executeSlowFunction ( ( value ) => { console . log ( `2. complete called` ) ; returnedValue = value ; } ) ; console . log ( `3. checking return value` ) ; expect ( returnedValue ) . toBe ( "completed" ) ; } ) ; } ) ; describe ( "async test with done " , ( ) => { let returnedValue ! ; beforeEach ( ( done ) => { let mockAsync = new MockAsync ( ) ; console . log ( `1. calling executeSlowFunction` ) ; mockAsync . executeSlowFunction ( ( value ) => { console . log ( `2. executeSlowFunction returned` ) ; returnedValue = value ; done ( ) ; } ) ; } ) ; it ( "should return value after 1 second" , ( ) => { console . log ( `3. checking returnedValue` ) ; expect ( returnedValue ) . toEqual ( "completed" ) ; } ) ; } ) ; class AsyncWithPromise { delayedPromise ( ) { return new Promise < string > ( ( resolve , reject ) => { setTimeout ( ( ) => { console . log ( `2. returning success` ) ; resolve ( "success" ) ; } , 1000 ) ; } ) ; } } describe ( "async test" , ( ) => { it ( "should wait 1 second for promise to resolve" , async ( ) => { let asyncWithPromise = new AsyncWithPromise ( ) ; console . log ( `1. calling delayedPromise` ) ; let returnValue = await asyncWithPromise . delayedPromise ( ) ; console . log ( `3. after await` ) ; expect ( returnValue ) . toEqual ( "success" ) ; } ) ; } ) ;