File tree Expand file tree Collapse file tree 3 files changed +25
-4
lines changed Expand file tree Collapse file tree 3 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -144,3 +144,23 @@ exports[`supports diffing single-line strings 1`] = `
144
144
+ bar
145
145
"
146
146
`;
147
+
148
+ exports[`supports diffing single-line strings 2`] = `
149
+ "Snapshot Diff:
150
+ - First value
151
+ + Second value
152
+
153
+ - foo
154
+ + bar
155
+ "
156
+ `;
157
+
158
+ exports[`supports diffing single-line strings 3`] = `
159
+ "Snapshot Diff:
160
+ - First value
161
+ + Second value
162
+
163
+ - foo
164
+ + bar
165
+ "
166
+ `;
Original file line number Diff line number Diff line change @@ -58,6 +58,8 @@ class Component extends React.Component<Props> {
58
58
59
59
test ( 'supports diffing single-line strings' , ( ) => {
60
60
expect ( snapshotDiff ( 'foo' , 'bar' ) ) . toMatchSnapshot ( ) ;
61
+ expect ( snapshotDiff ( 'foo\n' , 'bar' ) ) . toMatchSnapshot ( ) ;
62
+ expect ( snapshotDiff ( 'foo' , 'bar\n' ) ) . toMatchSnapshot ( ) ;
61
63
} ) ;
62
64
63
65
test ( 'collapses diffs and strips ansi by default' , ( ) => {
Original file line number Diff line number Diff line change @@ -51,12 +51,11 @@ const isReactComponent = (value: any) =>
51
51
value && value . $$typeof === reactElement ;
52
52
53
53
function diffStrings ( valueA : any , valueB : any , options : Options ) {
54
- const multiline =
55
- MULTILINE_REGEXP . test ( valueA ) && MULTILINE_REGEXP . test ( valueB ) ;
56
-
57
54
// jest-diff doesn't support single-line values, but we want to
58
- if ( typeof valueA === 'string' && typeof valueB === 'string' && ! multiline ) {
55
+ if ( typeof valueA === 'string' && ! MULTILINE_REGEXP . test ( valueA ) ) {
59
56
valueA += '\n' ; // eslint-disable-line no-param-reassign
57
+ }
58
+ if ( typeof valueB === 'string' && ! MULTILINE_REGEXP . test ( valueB ) ) {
60
59
valueB += '\n' ; // eslint-disable-line no-param-reassign
61
60
}
62
61
You can’t perform that action at this time.
0 commit comments