import { assert } from 'chai' ; import { ResolvablePromise } from './ResolvablePromise' ; describe ( 'ResolvablePromise' , function ( ) { it ( "Without awaiting the promise" , async function ( ) { const resolvablePromise = new ResolvablePromise < string > ( ) ; resolvablePromise . resolve ( 'hello' ) ; assert . equal ( await resolvablePromise , 'hello' ) ; } ) ; it ( "double await" , async function ( ) { const resolvablePromise = new ResolvablePromise < string > ( ) ; resolvablePromise . resolve ( 'hello' ) ; assert . equal ( await resolvablePromise , 'hello' ) ; assert . equal ( await resolvablePromise , 'hello' ) ; } ) ; it ( 'reject2' , async function ( ) { let resolve = ( ) => { } ; let reject = ( ) => { } ; const promise = new Promise < string > ( ( _resolve , _reject ) => { resolve = _resolve ; reject = _reject ; } ) ; let failures = 0 ; promise . catch ( err => ++ failures ) ; promise . catch ( err => ++ failures ) ; reject ( new Error ( "it broke" ) ) ; try { await promise ; } catch ( e ) { ++ failures ; } assert . equal ( failures , 3 ) ; promise . catch ( err => ++ failures ) ; try { await promise ; } catch ( e ) { ++ failures ; } assert . equal ( failures , 5 ) ; } ) ; } ) ;