@@ -89,13 +89,18 @@ export default class TestUtils {
8989 fs . writeFileSync ( tmpFilePath , `${ fileContentToSave . trim ( ) } \n` ) ;
9090 }
9191
92- public testToBe ( actual : any , expected : any , tmpFileName : string = null ) : void {
93- this . saveTmpFile ( tmpFileName , actual ) ;
94- expect ( actual ) . toBe ( expected ) ;
92+ public testToBe ( actual : any , expected : any , tmpFileName : string | null = null ) : void {
93+ if ( tmpFileName ) {
94+ this . saveTmpFile ( tmpFileName , actual ) ;
95+ }
96+ expect ( this . unitWhiteSpace ( actual ) ) . toBe ( this . unitWhiteSpace ( expected ) ) ;
9597 }
9698
97- public testMatchObject ( actual : Record < any , any > , expected : Record < any , any > , tmpFileName : string = null ) : void {
98- this . saveTmpFile ( tmpFileName , actual ) ;
99+ public testMatchObject ( actual : Record < any , any > , expected : Record < any , any > , tmpFileName : string | null = null ) : void {
100+ if ( tmpFileName ) {
101+ this . saveTmpFile ( tmpFileName , actual ) ;
102+ }
103+
99104 expect ( actual ) . toMatchObject ( expected ) ;
100105 }
101106
@@ -119,4 +124,16 @@ export default class TestUtils {
119124 this . testToBe ( actualContent , this . getExpectedFile ( `${ expectedFileName } .${ suffix } ` ) , `${ expectedFileName } .${ suffix } ` ) ;
120125 }
121126
127+ private unitWhiteSpace ( content : string ) {
128+ if ( typeof content !== 'string' ) {
129+ return content ;
130+ } ;
131+
132+ return content
133+ . replace ( / \r | \r n / g, '\n' )
134+ . replace ( / \n / g, '___NEWLINE___' )
135+ . replace ( / \s + / g, ' ' )
136+ . replace ( / _ _ _ N E W L I N E _ _ _ / g, '\n' ) ;
137+ }
138+
122139}
0 commit comments