File tree 2 files changed +32
-3
lines changed
2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change 1
1
import { diff } from './diff'
2
2
import { format } from './display'
3
- import { getOwnProperties , getType } from './helpers'
3
+ import { deepClone , getOwnProperties , getType } from './helpers'
4
4
import { stringify } from './stringify'
5
5
6
6
const IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@'
@@ -96,8 +96,13 @@ export function processError(err: any) {
96
96
if ( err . name )
97
97
err . nameStr = String ( err . name )
98
98
99
- if ( err . showDiff || ( err . showDiff === undefined && err . expected !== undefined && err . actual !== undefined ) )
100
- err . diff = diff ( err . expected , err . actual )
99
+ if ( err . showDiff || ( err . showDiff === undefined && err . expected !== undefined && err . actual !== undefined ) ) {
100
+ const clonedActual = deepClone ( err . actual , { forceWritable : true } )
101
+ const clonedExpected = deepClone ( err . expected , { forceWritable : true } )
102
+
103
+ const { replacedActual, replacedExpected } = replaceAsymmetricMatcher ( clonedActual , clonedExpected )
104
+ err . diff = diff ( replacedExpected , replacedActual )
105
+ }
101
106
102
107
if ( typeof err . expected !== 'string' )
103
108
err . expected = stringify ( err . expected , 10 )
Original file line number Diff line number Diff line change @@ -787,4 +787,28 @@ it('correctly prints diff', () => {
787
787
}
788
788
} )
789
789
790
+ it ( 'correctly prints diff with asymmetric matchers' , ( ) => {
791
+ try {
792
+ expect ( { a : 1 , b : 'string' } ) . toEqual ( {
793
+ a : expect . any ( Number ) ,
794
+ b : expect . any ( Function ) ,
795
+ } )
796
+ expect . unreachable ( )
797
+ }
798
+ catch ( err ) {
799
+ setupColors ( getDefaultColors ( ) )
800
+ const error = processError ( err )
801
+ expect ( error . diff ) . toMatchInlineSnapshot ( `
802
+ "- Expected
803
+ + Received
804
+
805
+ Object {
806
+ \\"a\\": Any<Number>,
807
+ - \\"b\\": Any<Function>,
808
+ + \\"b\\": \\"string\\",
809
+ }"
810
+ ` )
811
+ }
812
+ } )
813
+
790
814
it ( 'timeout' , ( ) => new Promise ( resolve => setTimeout ( resolve , 500 ) ) )
You can’t perform that action at this time.
0 commit comments