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

Function formatReceived

packages/expect/src/toThrowMatchers.ts:407–456  ·  view source on GitHub ↗
(
  label: string,
  thrown: Thrown | null,
  key: string,
  expected?: string | RegExp,
)

Source from the content-addressed store, hash-verified

405 `${label + printExpected(expected)}\n`;
406
407const formatReceived = (
408 label: string,
409 thrown: Thrown | null,
410 key: string,
411 expected?: string | RegExp,
412) => {
413 if (thrown === null) {
414 return '';
415 }
416
417 if (key === 'message') {
418 const message = thrown.message;
419
420 if (typeof expected === 'string') {
421 const index = message.indexOf(expected);
422 if (index !== -1) {
423 return `${
424 label +
425 printReceivedStringContainExpectedSubstring(
426 message,
427 index,
428 expected.length,
429 )
430 }\n`;
431 }
432 } else if (expected instanceof RegExp) {
433 return `${
434 label +
435 printReceivedStringContainExpectedResult(
436 message,
437 typeof expected.exec === 'function' ? expected.exec(message) : null,
438 )
439 }\n`;
440 }
441
442 return `${label + printReceived(message)}\n`;
443 }
444
445 if (key === 'name') {
446 return thrown.isError
447 ? `${label + printReceived(thrown.value.name)}\n`
448 : '';
449 }
450
451 if (key === 'value') {
452 return thrown.isError ? '' : `${label + printReceived(thrown.value)}\n`;
453 }
454
455 return '';
456};
457
458const formatStack = (thrown: Thrown | null) => {
459 if (thrown === null || !thrown.isError) {

Callers 6

toThrowExpectedRegExpFunction · 0.85
toThrowExpectedObjectFunction · 0.85
toThrowExpectedClassFunction · 0.85
toThrowExpectedStringFunction · 0.85
toThrowFunction · 0.85

Calls 4

printReceivedFunction · 0.90
execMethod · 0.80

Tested by

no test coverage detected