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

Function printReceivedResults

packages/expect/src/spyMatchers.ts:326–357  ·  view source on GitHub ↗
(
  label: string,
  expected: unknown,
  indexedResults: Array<IndexedResult>,
  isOnlyCall: boolean,
  iExpectedCall?: number,
)

Source from the content-addressed store, hash-verified

324// Return either empty string or one line per indexed result,
325// so additional empty line can separate from `Number of returns` which follows.
326const printReceivedResults = (
327 label: string,
328 expected: unknown,
329 indexedResults: Array<IndexedResult>,
330 isOnlyCall: boolean,
331 iExpectedCall?: number,
332) => {
333 if (indexedResults.length === 0) {
334 return '';
335 }
336
337 if (isOnlyCall && (iExpectedCall === 0 || iExpectedCall === undefined)) {
338 return `${label + printResult(indexedResults[0][1], expected)}\n`;
339 }
340
341 const printAligned = getRightAlignedPrinter(label);
342
343 return (
344 // eslint-disable-next-line prefer-template
345 label.replace(':', '').trim() +
346 '\n' +
347 indexedResults.reduce(
348 (printed: string, [i, result]: IndexedResult) =>
349 `${
350 printed +
351 printAligned(String(i + 1), i === iExpectedCall) +
352 printResult(result, expected)
353 }\n`,
354 '',
355 )
356 );
357};
358
359const createToHaveBeenCalledMatcher = (): MatcherFunction<[unknown]> =>
360 function (received: any, expected: unknown): SyncExpectationResult {

Calls 2

printResultFunction · 0.85
getRightAlignedPrinterFunction · 0.85

Tested by

no test coverage detected