Skip to content

Commit 3fd5434

Browse files
Fix array of strings being incorrectly converted to object when used with property matcher in snapshot.
1 parent a9c0e6b commit 3fd5434

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

e2e/__tests__/__snapshots__/snapshotSerializers.test.ts.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
exports[`Snapshot serializers renders snapshot 1`] = `
44
Object {
5+
"snapshot serializers works with array of strings in property matcher 1": "
6+
Object {
7+
\\"arrayOfStrings\\": Array [
8+
\\"stream\\",
9+
],
10+
}
11+
",
512
"snapshot serializers works with default serializers 1": "
613
<div
714
id=\\"foo\\"

e2e/__tests__/snapshotSerializers.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const runAndAssert = () => {
2020
'--no-cache',
2121
]);
2222
const json = result.json;
23-
expect(json.numTotalTests).toBe(7);
24-
expect(json.numPassedTests).toBe(7);
23+
expect(json.numTotalTests).toBe(8);
24+
expect(json.numPassedTests).toBe(8);
2525
expect(json.numFailedTests).toBe(0);
2626
expect(json.numPendingTests).toBe(0);
2727
expect(result.status).toBe(0);

e2e/snapshot-serializers/__tests__/snapshot.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,12 @@ describe('snapshot serializers', () => {
9191
});
9292
expect(test).toMatchSnapshot();
9393
});
94+
95+
it('works with array of strings in property matcher', () => {
96+
expect({
97+
arrayOfStrings: ['stream'],
98+
}).toMatchSnapshot({
99+
arrayOfStrings: ['stream'],
100+
});
101+
});
94102
});

packages/jest-snapshot/src/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ const deepMergeArray = (target: Array<any>, source: Array<any>) => {
194194
};
195195

196196
export const deepMerge = (target: any, source: any) => {
197-
const mergedOutput = {...target};
198197
if (isObject(target) && isObject(source)) {
198+
const mergedOutput = {...target};
199199
Object.keys(source).forEach(key => {
200200
if (isObject(source[key]) && !source[key].$$typeof) {
201201
if (!(key in target)) Object.assign(mergedOutput, {[key]: source[key]});
@@ -206,6 +206,8 @@ export const deepMerge = (target: any, source: any) => {
206206
Object.assign(mergedOutput, {[key]: source[key]});
207207
}
208208
});
209+
return mergedOutput;
210+
} else {
211+
return target;
209212
}
210-
return mergedOutput;
211213
};

0 commit comments

Comments
 (0)