(actual, expected, message, fn)
| 467 | } |
| 468 | |
| 469 | function expectedException(actual, expected, message, fn) { |
| 470 | let generatedMessage = false; |
| 471 | let throwError = false; |
| 472 | |
| 473 | if (typeof expected !== 'function') { |
| 474 | // Handle regular expressions. |
| 475 | if (isRegExp(expected)) { |
| 476 | const str = String(actual); |
| 477 | if (RegExpPrototypeExec(expected, str) !== null) |
| 478 | return; |
| 479 | |
| 480 | if (!message) { |
| 481 | generatedMessage = true; |
| 482 | message = 'The input did not match the regular expression ' + |
| 483 | `${inspect(expected)}. Input:\n\n${inspect(str)}\n`; |
| 484 | } |
| 485 | throwError = true; |
| 486 | // Handle primitives properly. |
| 487 | } else if (typeof actual !== 'object' || actual === null) { |
| 488 | const err = new AssertionError({ |
| 489 | actual, |
| 490 | expected, |
| 491 | message, |
| 492 | operator: 'deepStrictEqual', |
| 493 | stackStartFn: fn, |
| 494 | diff: this?.[kOptions]?.diff, |
| 495 | }); |
| 496 | err.operator = fn.name; |
| 497 | throw err; |
| 498 | } else { |
| 499 | // Handle validation objects. |
| 500 | const keys = ObjectKeys(expected); |
| 501 | // Special handle errors to make sure the name and the message are |
| 502 | // compared as well. |
| 503 | if (expected instanceof Error) { |
| 504 | ArrayPrototypePush(keys, 'name', 'message'); |
| 505 | } else if (keys.length === 0) { |
| 506 | throw new ERR_INVALID_ARG_VALUE('error', |
| 507 | expected, 'may not be an empty object'); |
| 508 | } |
| 509 | if (isDeepEqual === undefined) lazyLoadComparison(); |
| 510 | for (const key of keys) { |
| 511 | if (typeof actual[key] === 'string' && |
| 512 | isRegExp(expected[key]) && |
| 513 | RegExpPrototypeExec(expected[key], actual[key]) !== null) { |
| 514 | continue; |
| 515 | } |
| 516 | compareExceptionKey(actual, expected, key, message, keys, fn); |
| 517 | } |
| 518 | return; |
| 519 | } |
| 520 | // Guard instanceof against arrow functions as they don't have a prototype. |
| 521 | // Check for matching Error classes. |
| 522 | } else if (expected.prototype !== undefined && actual instanceof expected) { |
| 523 | return; |
| 524 | } else if (ObjectPrototypeIsPrototypeOf(Error, expected)) { |
| 525 | if (!message) { |
| 526 | generatedMessage = true; |
nothing calls this directly
no test coverage detected
searching dependent graphs…