import { timeoutPromiseAfter } from './timeout_promise_after' ; const delay = ( ms , result ) => new Promise ( ( resolve ) => setTimeout ( ( ) => resolve ( result ) , ms ) ) ; const delayRejection = ( ms , result ) => new Promise ( ( resolve , reject ) => setTimeout ( ( ) => reject ( result ) , ms ) ) ; describe ( 'Promise Timeout' , ( ) => { test ( 'resolves when wrapped promise resolves' , async ( ) => { return expect ( timeoutPromiseAfter ( delay ( 100 , 'OK' ) , 1000 , ( ) => 'TIMEOUT ERR' ) ) . resolves . toMatchInlineSnapshot ( `"OK"` ) ; } ) ; test ( 'reject when wrapped promise rejects' , async ( ) => { return expect ( timeoutPromiseAfter ( delayRejection ( 100 , 'ERR' ) , 1000 , ( ) => 'TIMEOUT ERR' ) ) . rejects . toMatchInlineSnapshot ( `"ERR"` ) ; } ) ; test ( 'reject it the timeout elapses' , async ( ) => { return expect ( timeoutPromiseAfter ( delay ( 1000 , 'OK' ) , 100 , ( ) => 'TIMEOUT ERR' ) ) . rejects . toMatchInlineSnapshot ( `"TIMEOUT ERR"` ) ; } ) ; } ) ;