@@ -21,6 +21,8 @@ const defaultOptions = {
2121 contextLines : - 1 , // Forces to use default from Jest
2222} ;
2323
24+ const SNAPSHOT_TITLE = 'Snapshot Diff:\n' ;
25+
2426const snapshotDiff = ( valueA : any , valueB : any , options ? : Options ) : string => {
2527 let difference ;
2628 const mergedOptions = Object . assign ( { } , defaultOptions , options ) ;
@@ -33,10 +35,11 @@ const snapshotDiff = (valueA: any, valueB: any, options?: Options): string => {
3335
3436 if ( ! mergedOptions . colors ) {
3537 const stripAnsi = require ( 'strip-ansi' ) ;
36- return stripAnsi ( difference ) ;
38+
39+ difference = stripAnsi ( difference ) ;
3740 }
3841
39- return difference ;
42+ return SNAPSHOT_TITLE + difference ;
4043} ;
4144
4245const isReactComponent = ( value : any ) =>
@@ -71,6 +74,18 @@ function toMatchDiffSnapshot(valueA: any, valueB: any, options?: Options) {
7174 return snapshot . toMatchSnapshot . call ( this , difference ) ;
7275}
7376
77+ function getSnapshotDiffSerializer ( ) {
78+ return {
79+ test ( value : any ) {
80+ return typeof value === 'string' && value . indexOf ( SNAPSHOT_TITLE ) === 0 ;
81+ } ,
82+ print ( value : any ) {
83+ return value ;
84+ } ,
85+ } ;
86+ }
87+
7488module . exports = snapshotDiff ;
7589module . exports . snapshotDiff = snapshotDiff ;
7690module . exports . toMatchDiffSnapshot = toMatchDiffSnapshot ;
91+ module . exports . getSnapshotDiffSerializer = getSnapshotDiffSerializer ;
0 commit comments