Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0a3fda0

Browse files
committed
address feedback
1 parent cb35442 commit 0a3fda0

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

‎__tests__/__snapshots__/snapshotDiff.test.js.snap‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,23 @@ exports[`supports diffing single-line strings 1`] = `
144144
+ bar
145145
"
146146
`;
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+
`;

‎__tests__/snapshotDiff.test.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class Component extends React.Component<Props> {
5858

5959
test('supports diffing single-line strings', () => {
6060
expect(snapshotDiff('foo', 'bar')).toMatchSnapshot();
61+
expect(snapshotDiff('foo\n', 'bar')).toMatchSnapshot();
62+
expect(snapshotDiff('foo', 'bar\n')).toMatchSnapshot();
6163
});
6264

6365
test('collapses diffs and strips ansi by default', () => {

‎src/index.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ const isReactComponent = (value: any) =>
5151
value && value.$$typeof === reactElement;
5252

5353
function diffStrings(valueA: any, valueB: any, options: Options) {
54-
const multiline =
55-
MULTILINE_REGEXP.test(valueA) && MULTILINE_REGEXP.test(valueB);
56-
5754
// jest-diff doesn't support single-line values, but we want to
58-
if (typeof valueA === 'string' && typeofvalueB==='string'&&!multiline) {
55+
if (typeof valueA === 'string' && !MULTILINE_REGEXP.test(valueA)) {
5956
valueA += '\n'; // eslint-disable-line no-param-reassign
57+
}
58+
if (typeof valueB === 'string' && !MULTILINE_REGEXP.test(valueB)) {
6059
valueB += '\n'; // eslint-disable-line no-param-reassign
6160
}
6261

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /