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

Function compareObjects

packages/jest-diff/src/index.ts:137–168  ·  view source on GitHub ↗
(
  a: Record<string, any>,
  b: Record<string, any>,
  options?: DiffOptions,
)

Source from the content-addressed store, hash-verified

135}
136
137function compareObjects(
138 a: Record<string, any>,
139 b: Record<string, any>,
140 options?: DiffOptions,
141) {
142 let difference;
143 let hasThrown = false;
144
145 try {
146 const formatOptions = getFormatOptions(FORMAT_OPTIONS, options);
147 difference = getObjectsDifference(a, b, formatOptions, options);
148 } catch {
149 hasThrown = true;
150 }
151
152 const noDiffMessage = getCommonMessage(NO_DIFF_MESSAGE, options);
153 // If the comparison yields no results, compare again but this time
154 // without calling `toJSON`. It's also possible that toJSON might throw.
155 if (difference === undefined || difference === noDiffMessage) {
156 const formatOptions = getFormatOptions(FALLBACK_FORMAT_OPTIONS, options);
157 difference = getObjectsDifference(a, b, formatOptions, options);
158
159 if (difference !== noDiffMessage && !hasThrown) {
160 difference = `${getCommonMessage(
161 SIMILAR_MESSAGE,
162 options,
163 )}\n\n${difference}`;
164 }
165 }
166
167 return difference;
168}
169
170function getFormatOptions(
171 formatOptions: PrettyFormatOptions,

Callers 1

diffFunction · 0.85

Calls 3

getFormatOptionsFunction · 0.85
getObjectsDifferenceFunction · 0.85
getCommonMessageFunction · 0.85

Tested by

no test coverage detected