( config: MatchSnapshotConfig, fromPromise?: boolean, )
| 475 | }; |
| 476 | |
| 477 | const _toThrowErrorMatchingSnapshot = ( |
| 478 | config: MatchSnapshotConfig, |
| 479 | fromPromise?: boolean, |
| 480 | ) => { |
| 481 | const {context, hint, inlineSnapshot, isInline, matcherName, received} = |
| 482 | config; |
| 483 | |
| 484 | context.dontThrow?.(); |
| 485 | |
| 486 | const {isNot, promise} = context; |
| 487 | |
| 488 | if (!fromPromise) { |
| 489 | if (typeof received !== 'function') { |
| 490 | const options: MatcherHintOptions = {isNot, promise}; |
| 491 | |
| 492 | throw new Error( |
| 493 | matcherErrorMessage( |
| 494 | matcherHint(matcherName, undefined, '', options), |
| 495 | `${RECEIVED_COLOR('received')} value must be a function`, |
| 496 | printWithType('Received', received, printReceived), |
| 497 | ), |
| 498 | ); |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | if (isNot) { |
| 503 | throw new Error( |
| 504 | matcherErrorMessage( |
| 505 | matcherHintFromConfig(config, false), |
| 506 | NOT_SNAPSHOT_MATCHERS, |
| 507 | ), |
| 508 | ); |
| 509 | } |
| 510 | |
| 511 | let error; |
| 512 | |
| 513 | if (fromPromise) { |
| 514 | error = received; |
| 515 | } else { |
| 516 | try { |
| 517 | received(); |
| 518 | } catch (receivedError) { |
| 519 | error = receivedError; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | if (error === undefined) { |
| 524 | // Because the received value is a function, this is not a matcher error. |
| 525 | throw new Error( |
| 526 | `${matcherHintFromConfig(config, false)}\n\n${DID_NOT_THROW}`, |
| 527 | ); |
| 528 | } |
| 529 | |
| 530 | let message = error.message; |
| 531 | while ('cause' in error) { |
| 532 | error = error.cause; |
| 533 | if (isError(error) || error instanceof Error) { |
| 534 | message += `\nCause: ${error.message}`; |
no test coverage detected