MCPcopy
hub / github.com/jestjs/jest / deepMerge

Function deepMerge

packages/jest-snapshot/src/utils.ts:111–135  ·  view source on GitHub ↗
(target: any, source: any)

Source from the content-addressed store, hash-verified

109
110// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
111export const deepMerge = (target: any, source: any): any => {
112 if (isObject(target) && isObject(source)) {
113 const mergedOutput = {...target};
114
115 for (const key of Object.keys(source)) {
116 if (isObject(source[key]) && !source[key].$$typeof) {
117 if (key in target) {
118 mergedOutput[key] = deepMerge(target[key], source[key]);
119 } else {
120 Object.assign(mergedOutput, {[key]: source[key]});
121 }
122 } else if (Array.isArray(source[key])) {
123 mergedOutput[key] = deepMergeArray(target[key], source[key]);
124 } else {
125 Object.assign(mergedOutput, {[key]: source[key]});
126 }
127 }
128
129 return mergedOutput;
130 } else if (Array.isArray(target) && Array.isArray(source)) {
131 return deepMergeArray(target, source);
132 }
133
134 return target;
135};
136
137const indent = (
138 snapshot: string,

Callers 3

_toMatchSnapshotFunction · 0.90
utils.test.tsFile · 0.90
deepMergeArrayFunction · 0.85

Calls 2

deepMergeArrayFunction · 0.85
isObjectFunction · 0.70

Tested by

no test coverage detected