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

Function makeThrowingMatcher

packages/expect/src/index.ts:275–395  ·  view source on GitHub ↗
(
  matcher: RawMatcherFn,
  isNot: boolean,
  promise: string,
  actual: any,
  err?: JestAssertionError,
)

Source from the content-addressed store, hash-verified

273 };
274
275const makeThrowingMatcher = (
276 matcher: RawMatcherFn,
277 isNot: boolean,
278 promise: string,
279 actual: any,
280 err?: JestAssertionError,
281): ThrowingMatcherFn =>
282 function throwingMatcher(...args): any {
283 let throws = true;
284 const utils: MatcherUtils['utils'] = {
285 ...matcherUtils,
286 iterableEquality,
287 subsetEquality,
288 };
289
290 const matcherUtilsThing: MatcherUtils = {
291 customTesters: getCustomEqualityTesters(),
292 // When throws is disabled, the matcher will not throw errors during test
293 // execution but instead add them to the global matcher state. If a
294 // matcher throws, test execution is normally stopped immediately. The
295 // snapshot matcher uses it because we want to log all snapshot
296 // failures in a test.
297 dontThrow: () => (throws = false),
298 equals,
299 utils,
300 };
301
302 const matcherContext: MatcherContext = {
303 ...getState<MatcherState>(),
304 ...matcherUtilsThing,
305 error: err,
306 isNot,
307 promise,
308 };
309
310 const processResult = (
311 result: SyncExpectationResult,
312 asyncError?: JestAssertionError,
313 ) => {
314 _validateResult(result);
315
316 getState().assertionCalls++;
317
318 if ((result.pass && isNot) || (!result.pass && !isNot)) {
319 // XOR
320 const message = getMessage(result.message);
321 let error;
322
323 if (err) {
324 error = err;
325 error.message = message;
326 } else if (asyncError) {
327 error = asyncError;
328 error.message = message;
329 } else {
330 error = new JestAssertionError(message);
331
332 // Try to remove this function from the stack trace frame.

Callers 3

expectFunction · 0.85
makeResolveMatcherFunction · 0.85
makeRejectMatcherFunction · 0.85

Calls 7

getCustomEqualityTestersFunction · 0.90
getStateFunction · 0.90
isPromiseFunction · 0.90
processResultFunction · 0.85
catchMethod · 0.80
thenMethod · 0.80
handleErrorFunction · 0.70

Tested by

no test coverage detected