| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -105,6 +105,14 @@ function innerFail(obj) { | |||
| 105 | 105 | throw new AssertionError(obj); | |
| 106 | 106 | } | |
| 107 | 107 | ||
| 108 | + /** | ||
| 109 | + * @param {any} actual | ||
| 110 | + * @param {any} expected | ||
| 111 | + * @param {string | Error} [message] | ||
| 112 | + * @param {string} [operator] | ||
| 113 | + * @param {Function} [stackStartFn] | ||
| 114 | + * @returns {never} | ||
| 115 | + */ | ||
| 108 | 116 | function fail(actual, expected, message, operator, stackStartFn) { | |
| 109 | 117 | const argsLen = arguments.length; | |
| 110 | 118 | ||
@@ -384,14 +392,24 @@ function innerOk(fn, argLen, value, message) { | |||
| 384 | 392 | } | |
| 385 | 393 | } | |
| 386 | 394 | ||
| 387 | - // Pure assertion tests whether a value is truthy, as determined | ||
| 388 | - // by !!value. | ||
| 395 | + /** | ||
| 396 | + * Pure assertion tests whether a value is truthy, as determined | ||
| 397 | + * by !!value. | ||
| 398 | + * @param {...any} args | ||
| 399 | + * @returns {void} | ||
| 400 | + */ | ||
| 389 | 401 | function ok(...args) { | |
| 390 | 402 | innerOk(ok, args.length, ...args); | |
| 391 | 403 | } | |
| 392 | 404 | assert.ok = ok; | |
| 393 | 405 | ||
| 394 | - // The equality assertion tests shallow, coercive equality with ==. | ||
| 406 | + /** | ||
| 407 | + * The equality assertion tests shallow, coercive equality with ==. | ||
| 408 | + * @param {any} actual | ||
| 409 | + * @param {any} expected | ||
| 410 | + * @param {string | Error} [message] | ||
| 411 | + * @returns {void} | ||
| 412 | + */ | ||
| 395 | 413 | /* eslint-disable no-restricted-properties */ | |
| 396 | 414 | assert.equal = function equal(actual, expected, message) { | |
| 397 | 415 | if (arguments.length < 2) { | |
@@ -409,8 +427,14 @@ assert.equal = function equal(actual, expected, message) { | |||
| 409 | 427 | } | |
| 410 | 428 | }; | |
| 411 | 429 | ||
| 412 | - // The non-equality assertion tests for whether two objects are not | ||
| 413 | - // equal with !=. | ||
| 430 | + /** | ||
| 431 | + * The non-equality assertion tests for whether two objects are not | ||
| 432 | + * equal with !=. | ||
| 433 | + * @param {any} actual | ||
| 434 | + * @param {any} expected | ||
| 435 | + * @param {string | Error} [message] | ||
| 436 | + * @returns {void} | ||
| 437 | + */ | ||
| 414 | 438 | assert.notEqual = function notEqual(actual, expected, message) { | |
| 415 | 439 | if (arguments.length < 2) { | |
| 416 | 440 | throw new ERR_MISSING_ARGS('actual', 'expected'); | |
@@ -427,7 +451,13 @@ assert.notEqual = function notEqual(actual, expected, message) { | |||
| 427 | 451 | } | |
| 428 | 452 | }; | |
| 429 | 453 | ||
| 430 | - // The equivalence assertion tests a deep equality relation. | ||
| 454 | + /** | ||
| 455 | + * The deep equivalence assertion tests a deep equality relation. | ||
| 456 | + * @param {any} actual | ||
| 457 | + * @param {any} expected | ||
| 458 | + * @param {string | Error} [message] | ||
| 459 | + * @returns {void} | ||
| 460 | + */ | ||
| 431 | 461 | assert.deepEqual = function deepEqual(actual, expected, message) { | |
| 432 | 462 | if (arguments.length < 2) { | |
| 433 | 463 | throw new ERR_MISSING_ARGS('actual', 'expected'); | |
@@ -444,7 +474,13 @@ assert.deepEqual = function deepEqual(actual, expected, message) { | |||
| 444 | 474 | } | |
| 445 | 475 | }; | |
| 446 | 476 | ||
| 447 | - // The non-equivalence assertion tests for any deep inequality. | ||
| 477 | + /** | ||
| 478 | + * The deep non-equivalence assertion tests for any deep inequality. | ||
| 479 | + * @param {any} actual | ||
| 480 | + * @param {any} expected | ||
| 481 | + * @param {string | Error} [message] | ||
| 482 | + * @returns {void} | ||
| 483 | + */ | ||
| 448 | 484 | assert.notDeepEqual = function notDeepEqual(actual, expected, message) { | |
| 449 | 485 | if (arguments.length < 2) { | |
| 450 | 486 | throw new ERR_MISSING_ARGS('actual', 'expected'); | |
@@ -462,6 +498,14 @@ assert.notDeepEqual = function notDeepEqual(actual, expected, message) { | |||
| 462 | 498 | }; | |
| 463 | 499 | /* eslint-enable */ | |
| 464 | 500 | ||
| 501 | + /** | ||
| 502 | + * The deep strict equivalence assertion tests a deep strict equality | ||
| 503 | + * relation. | ||
| 504 | + * @param {any} actual | ||
| 505 | + * @param {any} expected | ||
| 506 | + * @param {string | Error} [message] | ||
| 507 | + * @returns {void} | ||
| 508 | + */ | ||
| 465 | 509 | assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) { | |
| 466 | 510 | if (arguments.length < 2) { | |
| 467 | 511 | throw new ERR_MISSING_ARGS('actual', 'expected'); | |
@@ -478,6 +522,14 @@ assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) { | |||
| 478 | 522 | } | |
| 479 | 523 | }; | |
| 480 | 524 | ||
| 525 | + /** | ||
| 526 | + * The deep strict non-equivalence assertion tests for any deep strict | ||
| 527 | + * inequality. | ||
| 528 | + * @param {any} actual | ||
| 529 | + * @param {any} expected | ||
| 530 | + * @param {string | Error} [message] | ||
| 531 | + * @returns {void} | ||
| 532 | + */ | ||
| 481 | 533 | assert.notDeepStrictEqual = notDeepStrictEqual; | |
| 482 | 534 | function notDeepStrictEqual(actual, expected, message) { | |
| 483 | 535 | if (arguments.length < 2) { | |
@@ -495,6 +547,13 @@ function notDeepStrictEqual(actual, expected, message) { | |||
| 495 | 547 | } | |
| 496 | 548 | } | |
| 497 | 549 | ||
| 550 | + /** | ||
| 551 | + * The strict equivalence assertion tests a strict equality relation. | ||
| 552 | + * @param {any} actual | ||
| 553 | + * @param {any} expected | ||
| 554 | + * @param {string | Error} [message] | ||
| 555 | + * @returns {void} | ||
| 556 | + */ | ||
| 498 | 557 | assert.strictEqual = function strictEqual(actual, expected, message) { | |
| 499 | 558 | if (arguments.length < 2) { | |
| 500 | 559 | throw new ERR_MISSING_ARGS('actual', 'expected'); | |
@@ -510,6 +569,13 @@ assert.strictEqual = function strictEqual(actual, expected, message) { | |||
| 510 | 569 | } | |
| 511 | 570 | }; | |
| 512 | 571 | ||
| 572 | + /** | ||
| 573 | + * The strict non-equivalence assertion tests for any strict inequality. | ||
| 574 | + * @param {any} actual | ||
| 575 | + * @param {any} expected | ||
| 576 | + * @param {string | Error} [message] | ||
| 577 | + * @returns {void} | ||
| 578 | + */ | ||
| 513 | 579 | assert.notStrictEqual = function notStrictEqual(actual, expected, message) { | |
| 514 | 580 | if (arguments.length < 2) { | |
| 515 | 581 | throw new ERR_MISSING_ARGS('actual', 'expected'); | |
@@ -820,22 +886,51 @@ function expectsNoError(stackStartFn, actual, error, message) { | |||
| 820 | 886 | throw actual; | |
| 821 | 887 | } | |
| 822 | 888 | ||
| 889 | + /** | ||
| 890 | + * Expects the function `promiseFn` to throw an error. | ||
| 891 | + * @param {() => any} promiseFn | ||
| 892 | + * @param {...any} [args] | ||
| 893 | + * @returns {void} | ||
| 894 | + */ | ||
| 823 | 895 | assert.throws = function throws(promiseFn, ...args) { | |
| 824 | 896 | expectsError(throws, getActual(promiseFn), ...args); | |
| 825 | 897 | }; | |
| 826 | 898 | ||
| 899 | + /** | ||
| 900 | + * Expects `promiseFn` function or its value to reject. | ||
| 901 | + * @param {() => Promise<any>} promiseFn | ||
| 902 | + * @param {...any} [args] | ||
| 903 | + * @returns {Promise<void>} | ||
| 904 | + */ | ||
| 827 | 905 | assert.rejects = async function rejects(promiseFn, ...args) { | |
| 828 | 906 | expectsError(rejects, await waitForActual(promiseFn), ...args); | |
| 829 | 907 | }; | |
| 830 | 908 | ||
| 909 | + /** | ||
| 910 | + * Asserts that the function `fn` does not throw an error. | ||
| 911 | + * @param {() => any} fn | ||
| 912 | + * @param {...any} [args] | ||
| 913 | + * @returns {void} | ||
| 914 | + */ | ||
| 831 | 915 | assert.doesNotThrow = function doesNotThrow(fn, ...args) { | |
| 832 | 916 | expectsNoError(doesNotThrow, getActual(fn), ...args); | |
| 833 | 917 | }; | |
| 834 | 918 | ||
| 919 | + /** | ||
| 920 | + * Expects `fn` or its value to not reject. | ||
| 921 | + * @param {() => Promise<any>} fn | ||
| 922 | + * @param {...any} [args] | ||
| 923 | + * @returns {Promise<void>} | ||
| 924 | + */ | ||
| 835 | 925 | assert.doesNotReject = async function doesNotReject(fn, ...args) { | |
| 836 | 926 | expectsNoError(doesNotReject, await waitForActual(fn), ...args); | |
| 837 | 927 | }; | |
| 838 | 928 | ||
| 929 | + /** | ||
| 930 | + * Throws `value` if the value is not `null` or `undefined`. | ||
| 931 | + * @param {any} err | ||
| 932 | + * @returns {void} | ||
| 933 | + */ | ||
| 839 | 934 | assert.ifError = function ifError(err) { | |
| 840 | 935 | if (err !== null && err !== undefined) { | |
| 841 | 936 | let message = 'ifError got unwanted exception: '; | |
@@ -919,24 +1014,44 @@ function internalMatch(string, regexp, message, fn) { | |||
| 919 | 1014 | } | |
| 920 | 1015 | } | |
| 921 | 1016 | ||
| 1017 | + /** | ||
| 1018 | + * Expects the `string` input to match the regular expression. | ||
| 1019 | + * @param {string} string | ||
| 1020 | + * @param {RegExp} regexp | ||
| 1021 | + * @param {string | Error} [message] | ||
| 1022 | + * @returns {void} | ||
| 1023 | + */ | ||
| 922 | 1024 | assert.match = function match(string, regexp, message) { | |
| 923 | 1025 | internalMatch(string, regexp, message, match); | |
| 924 | 1026 | }; | |
| 925 | 1027 | ||
| 1028 | + /** | ||
| 1029 | + * Expects the `string` input not to match the regular expression. | ||
| 1030 | + * @param {string} string | ||
| 1031 | + * @param {RegExp} regexp | ||
| 1032 | + * @param {string | Error} [message] | ||
| 1033 | + * @returns {void} | ||
| 1034 | + */ | ||
| 926 | 1035 | assert.doesNotMatch = function doesNotMatch(string, regexp, message) { | |
| 927 | 1036 | internalMatch(string, regexp, message, doesNotMatch); | |
| 928 | 1037 | }; | |
| 929 | 1038 | ||
| 930 | 1039 | assert.CallTracker = CallTracker; | |
| 931 | 1040 | ||
| 932 | - // Expose a strict only variant of assert | ||
| 1041 | + /** | ||
| 1042 | + * Expose a strict only variant of assert. | ||
| 1043 | + * @param {...any} args | ||
| 1044 | + * @returns {void} | ||
| 1045 | + */ | ||
| 933 | 1046 | function strict(...args) { | |
| 934 | 1047 | innerOk(strict, args.length, ...args); | |
| 935 | 1048 | } | |
| 1049 | + | ||
| 936 | 1050 | assert.strict = ObjectAssign(strict, assert, { | |
| 937 | 1051 | equal: assert.strictEqual, | |
| 938 | 1052 | deepEqual: assert.deepStrictEqual, | |
| 939 | 1053 | notEqual: assert.notStrictEqual, | |
| 940 | 1054 | notDeepEqual: assert.notDeepStrictEqual | |
| 941 | 1055 | }); | |
| 1056 | + | ||
| 942 | 1057 | assert.strict.strict = assert.strict; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments