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

Function printDiffCall

packages/expect/src/spyMatchers.ts:221–260  ·  view source on GitHub ↗
(
  expected: Array<unknown>,
  received: Array<unknown>,
  expand: boolean,
)

Source from the content-addressed store, hash-verified

219const indentation = 'Received'.replaceAll(/\w/g, ' ');
220
221const printDiffCall = (
222 expected: Array<unknown>,
223 received: Array<unknown>,
224 expand: boolean,
225) =>
226 received
227 .map((arg, i) => {
228 if (i < expected.length) {
229 if (isEqualValue(expected[i], arg)) {
230 return `${indentation} ${printCommon(arg)},`;
231 }
232
233 if (isLineDiffableArg(expected[i], arg)) {
234 const difference = diff(expected[i], arg, {expand});
235
236 if (
237 typeof difference === 'string' &&
238 difference.includes('- Expected') &&
239 difference.includes('+ Received')
240 ) {
241 // Display diff with indentation.
242 // Omit annotation in case multiple args have diff.
243 return `${difference
244 .split('\n')
245 .slice(3)
246 .map(line => indentation + line)
247 .join('\n')},`;
248 }
249 }
250 }
251
252 // Display + only if received arg has no corresponding expected arg.
253 return `${
254 indentation +
255 (i < expected.length
256 ? ` ${printReceived(arg)}`
257 : RECEIVED_COLOR(`+ ${stringify(arg)}`))
258 },`;
259 })
260 .join('\n');
261
262const isLineDiffableCall = (
263 expected: Array<unknown>,

Callers 1

Calls 6

diffFunction · 0.90
printReceivedFunction · 0.90
stringifyFunction · 0.90
isEqualValueFunction · 0.85
printCommonFunction · 0.85
isLineDiffableArgFunction · 0.85

Tested by

no test coverage detected