@@ -19,11 +19,25 @@ function compareStrings(a: string, b: string): boolean {
19
19
return a . includes ( b ) ;
20
20
}
21
21
22
+ /** Ignore whitespace, trailing commas, and leading pipes */
23
+ function similarize ( str : string ) : string {
24
+ return (
25
+ oneLine `${ str } `
26
+ // Trim trailing commas
27
+ . replace ( / \s * , ( \s * [ ) } ] ) / g, '$1' )
28
+ // Remove leading pipes
29
+ . replace ( / ( [ < : , = ( ] ) \s * (?: \| \s * ) ? / g, '$1' )
30
+ // Remove spaces around brackets and semicolons
31
+ . replace ( / \s * ( [ [ \] ( ) { } < > ; ] ) \s * / g, '$1' )
32
+ // Replace multiple spaces with a single space
33
+ . replace ( / \s \s + / g, ' ' )
34
+ ) ;
35
+ }
36
+
22
37
expect . extend ( {
23
38
toBeSimilarStringTo ( received : string , expected : string ) {
24
- // Ignore whitespace and trailing commas
25
- const strippedReceived = oneLine `${ received } ` . replace ( / \s \s + / g, ' ' ) . replace ( / \s * , ( \s * [ ) } ] ) / , '$1' ) ;
26
- const strippedExpected = oneLine `${ expected } ` . replace ( / \s \s + / g, ' ' ) . replace ( / \s * , ( \s * [ ) } ] ) / , '$1' ) ;
39
+ const strippedReceived = similarize ( received ) ;
40
+ const strippedExpected = similarize ( expected ) ;
27
41
28
42
if ( compareStrings ( strippedReceived , strippedExpected ) ) {
29
43
return {
0 commit comments