File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed
packages/jest-snapshot/src Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ const {
1919 keyToTestName,
2020 serialize,
2121 testNameToKey,
22+ unescape,
2223} = require ( './utils' ) ;
2324const fileExists = require ( 'jest-file-exists' ) ;
2425const fs = require ( 'fs' ) ;
@@ -158,9 +159,9 @@ class SnapshotState {
158159 if ( ! pass ) {
159160 this . unmatched ++ ;
160161 return {
161- actual : receivedSerialized ,
162+ actual : unescape ( receivedSerialized ) ,
162163 count,
163- expected,
164+ expected : unescape ( expected ) ,
164165 pass : false ,
165166 } ;
166167 } else {
Original file line number Diff line number Diff line change @@ -66,6 +66,12 @@ const serialize = (data: any): string => {
6666 } ) ) ;
6767} ;
6868
69+ const unescape = ( data : any ) : string => {
70+ return data
71+ . replace ( / \\ ( " ) / g, '$1' ) // unescape double quotes
72+ . replace ( / \\ ( [ \\ ^ $ * + ? . ( ) | [ \] { } ] ) / g, '$1' ) ; // then unescape RegExp
73+ } ;
74+
6975const printBacktickString = ( str : string ) => {
7076 return '`' + str . replace ( / ` | \\ | \$ { / g, '\\$&' ) + '`' ;
7177} ;
@@ -102,4 +108,5 @@ module.exports = {
102108 saveSnapshotFile,
103109 serialize,
104110 testNameToKey,
111+ unescape,
105112} ;
You can’t perform that action at this time.
0 commit comments