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

Function toThrow

packages/expect/src/toThrowMatchers.ts:378–402  ·  view source on GitHub ↗
(
  matcherName: string,
  options: MatcherHintOptions,
  thrown: Thrown | null,
)

Source from the content-addressed store, hash-verified

376};
377
378const toThrow = (
379 matcherName: string,
380 options: MatcherHintOptions,
381 thrown: Thrown | null,
382): SyncExpectationResult => {
383 const pass = thrown !== null;
384
385 const message = pass
386 ? () =>
387 // eslint-disable-next-line prefer-template
388 matcherHint(matcherName, undefined, '', options) +
389 '\n\n' +
390 (thrown !== null && thrown.hasMessage
391 ? formatReceived('Error name: ', thrown, 'name') +
392 formatReceived('Error message: ', thrown, 'message') +
393 formatStack(thrown)
394 : formatReceived('Thrown value: ', thrown, 'value'))
395 : () =>
396 // eslint-disable-next-line prefer-template
397 matcherHint(matcherName, undefined, '', options) +
398 '\n\n' +
399 DID_NOT_THROW;
400
401 return {message, pass};
402};
403
404const formatExpected = (label: string, expected: unknown) =>
405 `${label + printExpected(expected)}\n`;

Callers 1

createMatcherFunction · 0.85

Calls 3

matcherHintFunction · 0.90
formatReceivedFunction · 0.85
formatStackFunction · 0.85

Tested by

no test coverage detected