/**
 * isPromise detects whether given object is a promise or not.
 */ const isPromise = < T extends any > ( obj ) : obj is PromiseLike < T > => ! ! obj && ( typeof obj === "object" || typeof obj === "function" ) && typeof obj . then === "function" ; param func const wrapMatcher = ( func ) => { const wrappedMatcher = { } ; const keys = Object . keys ( func ) ; keys . forEach ( ( k ) => { if ( typeof func [ k ] === "function" ) { wrappedMatcher [ k ] = ( ... args ) => { try { const result = func [ k ] ( ... args ) ; if ( isPromise ( result ) ) { return result . then ( undefined , ( e ) => { Error . captureStackTrace ( e , wrappedMatcher [ k ] ) ; fail ( e ) ; throw e ; } ) ; } return result ; } catch ( e ) { Error . captureStackTrace ( e , wrappedMatcher [ k ] ) ; fail ( e ) ; throw e ; } } ; } else { wrappedMatcher [ k ] = wrapMatcher ( func [ k ] ) ; } } ) ; return wrappedMatcher ; } ; const expectAndFail = ( ... args ) => { const matcher = ( global as any ) . expect ( ... args ) ; return wrapMatcher ( matcher ) ; } ; export default expectAndFail ;