export { } ; declare global { namespace jest { interface Matchers < R > { toMatchString ( actual ) : R ; toMatchStringArray ( actual ) : R ; } } } function deIndent ( str ) { str = str . slice ( str . search ( /[^\n]/ ) ) ; while ( str . charAt ( str . length - 1 ) === '\n' || str . charAt ( str . length - 1 ) === ' ' ) { str = str . slice ( 0 , str . length - 1 ) ; } const indent = str . search ( /[^ ]/ ) ; return str . split ( '\n' ) . map ( line => line . slice ( indent ) ) . join ( '\n' ) ; } expect . extend ( { toMatchString ( expected , received ) { received = deIndent ( received ) ; if ( expected . charAt ( expected . length - 1 ) === '\n' ) { received = received + '\n' ; } const pass = this . equals ( expected , received ) ; const message = pass ? ( ) => this . utils . matcherHint ( 'toMatchString' , undefined , undefined ) + '\n\n' + `Expected: not ${ this . printExpected ( expected ) }` : ( ) => { return ( this . utils . matcherHint ( 'toMatchString' , undefined , undefined ) + '\n\n' + this . utils . printDiffOrStringify ( expected , received , 'Expected' , 'Received' , true ) ) ; } ; return { received , expected , message , name : 'toMatchString' , pass } ; } , toMatchStringArray ( expected , received ) { if ( expected . length !== received . length ) { const message = ( ) => this . utils . matcherHint ( 'toMatchStringArray' , undefined , undefined ) + `\n\nExpected an array of size ${ expected . length } but got one of size ${ received . length }\n\n` + this . utils . printDiffOrStringify ( expected , received , 'Expected' , 'Received' , true ) ; return { received , expected , message , name : 'toMatchStringArray' , pass : false } ; } let pass = true ; const messages = [ ] ; for ( let i = 0 ; i < expected . length ; i ++ ) { const exp = expected [ i ] ; const rec = deIndent ( received [ i ] ) ; if ( ! this . equals ( exp , rec ) ) { pass = false ; messages . push ( `Elements at index ${ i } do no match:\n` + this . utils . printDiffOrStringify ( exp , rec , 'Expected' , 'Received' , true ) ) ; } } const message = ( ) => this . utils . matcherHint ( 'toMatchString' , undefined , undefined ) + '\n\n' + ( pass ? `Expected: not ${ this . printExpected ( expected ) }` : messages . join ( '\n\n' ) ) ; return { received , expected , message , name : 'toMatchStringArray' , pass } ; } } ) ;