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

Function toThrowExpectedString

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

Source from the content-addressed store, hash-verified

339};
340
341const toThrowExpectedString = (
342 matcherName: string,
343 options: MatcherHintOptions,
344 thrown: Thrown | null,
345 expected: string,
346): SyncExpectationResult => {
347 const pass = thrown !== null && thrown.message.includes(expected);
348
349 const message = pass
350 ? () =>
351 // eslint-disable-next-line prefer-template
352 matcherHint(matcherName, undefined, undefined, options) +
353 '\n\n' +
354 formatExpected('Expected substring: not ', expected) +
355 (thrown !== null && thrown.hasMessage
356 ? formatReceived(
357 'Received message: ',
358 thrown,
359 'message',
360 expected,
361 ) + formatStack(thrown)
362 : formatReceived('Received value: ', thrown, 'value'))
363 : () =>
364 // eslint-disable-next-line prefer-template
365 matcherHint(matcherName, undefined, undefined, options) +
366 '\n\n' +
367 formatExpected('Expected substring: ', expected) +
368 (thrown === null
369 ? `\n${DID_NOT_THROW}`
370 : thrown.hasMessage
371 ? formatReceived('Received message: ', thrown, 'message') +
372 formatStack(thrown)
373 : formatReceived('Received value: ', thrown, 'value'));
374
375 return {message, pass};
376};
377
378const toThrow = (
379 matcherName: string,

Callers 1

createMatcherFunction · 0.85

Calls 4

matcherHintFunction · 0.90
formatExpectedFunction · 0.85
formatReceivedFunction · 0.85
formatStackFunction · 0.85

Tested by

no test coverage detected