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

Function toThrowExpectedClass

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

Source from the content-addressed store, hash-verified

285};
286
287const toThrowExpectedClass = (
288 matcherName: string,
289 options: MatcherHintOptions,
290 thrown: Thrown | null,
291 expected: Function,
292): SyncExpectationResult => {
293 const pass = thrown !== null && thrown.value instanceof expected;
294
295 const message = pass
296 ? () =>
297 // eslint-disable-next-line prefer-template
298 matcherHint(matcherName, undefined, undefined, options) +
299 '\n\n' +
300 printExpectedConstructorNameNot('Expected constructor', expected) +
301 (thrown !== null &&
302 thrown.value != null &&
303 typeof thrown.value.constructor === 'function' &&
304 thrown.value.constructor !== expected
305 ? printReceivedConstructorNameNot(
306 'Received constructor',
307 thrown.value.constructor,
308 expected,
309 )
310 : '') +
311 '\n' +
312 (thrown !== null && thrown.hasMessage
313 ? formatReceived('Received message: ', thrown, 'message') +
314 formatStack(thrown)
315 : formatReceived('Received value: ', thrown, 'value'))
316 : () =>
317 // eslint-disable-next-line prefer-template
318 matcherHint(matcherName, undefined, undefined, options) +
319 '\n\n' +
320 printExpectedConstructorName('Expected constructor', expected) +
321 (thrown === null
322 ? `\n${DID_NOT_THROW}`
323 : `${
324 thrown.value != null &&
325 typeof thrown.value.constructor === 'function'
326 ? printReceivedConstructorName(
327 'Received constructor',
328 thrown.value.constructor,
329 )
330 : ''
331 }\n${
332 thrown.hasMessage
333 ? formatReceived('Received message: ', thrown, 'message') +
334 formatStack(thrown)
335 : formatReceived('Received value: ', thrown, 'value')
336 }`);
337
338 return {message, pass};
339};
340
341const toThrowExpectedString = (
342 matcherName: string,

Callers 1

createMatcherFunction · 0.85

Calls 7

matcherHintFunction · 0.90
formatReceivedFunction · 0.85
formatStackFunction · 0.85

Tested by

no test coverage detected