import { EXPECTED_COLOR , printExpected } from 'jest-matcher-utils' ; import { ApplyProp , Expectation , ReturnValue } from './expectation/expectation' ; import { isMatcher } from './expectation/matcher' ; import { Property } from './proxy' ; export const printProperty = ( property ) => { if ( property === ApplyProp ) { return '' ; } if ( typeof property === 'symbol' ) { return `[${ property . toString ( ) }]` ; } return `.${ property }` ; } ; export const printArg = ( arg ) : string => isMatcher ( arg ) ? arg . toJSON ( ) : printExpected ( arg ) ; export const printCall = ( property , args ) => { const prettyArgs = args . map ( ( arg ) => printArg ( arg ) ) . join ( ', ' ) ; const prettyProperty = printProperty ( property ) ; return `${ prettyProperty }(${ prettyArgs })` ; } ; export const printReturns = ( { isError , isPromise , value } , min , max ) => { let thenPrefix = '' ; if ( isPromise ) { if ( isError ) { thenPrefix += 'thenReject' ; } else { thenPrefix += 'thenResolve' ; } } else if ( isError ) { thenPrefix += 'thenThrow' ; } else { thenPrefix += 'thenReturn' ; } return `.${ thenPrefix }(${ printExpected ( value ) }).between(${ min }, ${ max })` ; } ; export const printWhen = ( property , args ) => { if ( args ) { return `when(${ EXPECTED_COLOR ( `mock${ printCall ( property , args ) }` ) })` ; } return `when(${ EXPECTED_COLOR ( `mock${ printProperty ( property ) }` ) })` ; } ; export const printExpectation = ( property , args , returnValue , min , max ) => `${ printWhen ( property , args ) }${ printReturns ( returnValue , min , max ) }` ; export const printRemainingExpectations = ( expectations ) => expectations . length ? `Remaining unmet expectations:
 - ${ expectations . map ( ( e ) => e . toJSON ( ) ) . join ( '\n - ' ) }` : 'There are no remaining unmet expectations.' ;