| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -123,6 +123,14 @@ function innerFail(obj) { | |||
| 123 | 123 | throw new AssertionError(obj); | |
| 124 | 124 | } | |
| 125 | 125 | ||
| 126 | + /** | ||
| 127 | + * @param {any} actual | ||
| 128 | + * @param {any} expected | ||
| 129 | + * @param {string | Error} [message] | ||
| 130 | + * @param {string} [operator] | ||
| 131 | + * @param {Function} [stackStartFn] | ||
| 132 | + * @returns {never} | ||
| 133 | + */ | ||
| 126 | 134 | function fail(actual, expected, message, operator, stackStartFn) { | |
| 127 | 135 | const argsLen = arguments.length; | |
| 128 | 136 | ||
@@ -405,14 +413,24 @@ function innerOk(fn, argLen, value, message) { | |||
| 405 | 413 | } | |
| 406 | 414 | } | |
| 407 | 415 | ||
| 408 | - // Pure assertion tests whether a value is truthy, as determined | ||
| 409 | - // by !!value. | ||
| 416 | + /** | ||
| 417 | + * Pure assertion tests whether a value is truthy, as determined | ||
| 418 | + * by !!value. | ||
| 419 | + * @param {...any} args | ||
| 420 | + * @returns {void} | ||
| 421 | + */ | ||
| 410 | 422 | function ok(...args) { | |
| 411 | 423 | innerOk(ok, args.length, ...args); | |
| 412 | 424 | } | |
| 413 | 425 | assert.ok = ok; | |
| 414 | 426 | ||
| 415 | - // The equality assertion tests shallow, coercive equality with ==. | ||
| 427 | + /** | ||
| 428 | + * The equality assertion tests shallow, coercive equality with ==. | ||
| 429 | + * @param {any} actual | ||
| 430 | + * @param {any} expected | ||
| 431 | + * @param {string | Error} [message] | ||
| 432 | + * @returns {void} | ||
| 433 | + */ | ||
| 416 | 434 | /* eslint-disable no-restricted-properties */ | |
| 417 | 435 | assert.equal = function equal(actual, expected, message) { | |
| 418 | 436 | if (arguments.length < 2) { | |
@@ -430,8 +448,14 @@ assert.equal = function equal(actual, expected, message) { | |||
| 430 | 448 | } | |
| 431 | 449 | }; | |
| 432 | 450 | ||
| 433 | - // The non-equality assertion tests for whether two objects are not | ||
| 434 | - // equal with !=. | ||
| 451 | + /** | ||
| 452 | + * The non-equality assertion tests for whether two objects are not | ||
| 453 | + * equal with !=. | ||
| 454 | + * @param {any} actual | ||
| 455 | + * @param {any} expected | ||
| 456 | + * @param {string | Error} [message] | ||
| 457 | + * @returns {void} | ||
| 458 | + */ | ||
| 435 | 459 | assert.notEqual = function notEqual(actual, expected, message) { | |
| 436 | 460 | if (arguments.length < 2) { | |
| 437 | 461 | throw new ERR_MISSING_ARGS('actual', 'expected'); | |
@@ -448,7 +472,13 @@ assert.notEqual = function notEqual(actual, expected, message) { | |||
| 448 | 472 | } | |
| 449 | 473 | }; | |
| 450 | 474 | ||
| 451 | - // The equivalence assertion tests a deep equality relation. | ||
| 475 | + /** | ||
| 476 | + * The deep equivalence assertion tests a deep equality relation. | ||
| 477 | + * @param {any} actual | ||
| 478 | + * @param {any} expected | ||
| 479 | + * @param {string | Error} [message] | ||
| 480 | + * @returns {void} | ||
| 481 | + */ | ||
| 452 | 482 | assert.deepEqual = function deepEqual(actual, expected, message) { | |
| 453 | 483 | if (arguments.length < 2) { | |
| 454 | 484 | throw new ERR_MISSING_ARGS('actual', 'expected'); | |
@@ -465,7 +495,13 @@ assert.deepEqual = function deepEqual(actual, expected, message) { | |||
| 465 | 495 | } | |
| 466 | 496 | }; | |
| 467 | 497 | ||
| 468 | - // The non-equivalence assertion tests for any deep inequality. | ||
| 498 | + /** | ||
| 499 | + * The deep non-equivalence assertion tests for any deep inequality. | ||
| 500 | + * @param {any} actual | ||
| 501 | + * @param {any} expected | ||
| 502 | + * @param {string | Error} [message] | ||
| 503 | + * @returns {void} | ||
| 504 | + */ | ||
| 469 | 505 | assert.notDeepEqual = function notDeepEqual(actual, expected, message) { | |
| 470 | 506 | if (arguments.length < 2) { | |
| 471 | 507 | throw new ERR_MISSING_ARGS('actual', 'expected'); | |
@@ -483,6 +519,14 @@ assert.notDeepEqual = function notDeepEqual(actual, expected, message) { | |||
| 483 | 519 | }; | |
| 484 | 520 | /* eslint-enable */ | |
| 485 | 521 | ||
| 522 | + /** | ||
| 523 | + * The deep strict equivalence assertion tests a deep strict equality | ||
| 524 | + * relation. | ||
| 525 | + * @param {any} actual | ||
| 526 | + * @param {any} expected | ||
| 527 | + * @param {string | Error} [message] | ||
| 528 | + * @returns {void} | ||
| 529 | + */ | ||
| 486 | 530 | assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) { | |
| 487 | 531 | if (arguments.length < 2) { | |
| 488 | 532 | throw new ERR_MISSING_ARGS('actual', 'expected'); | |
@@ -499,6 +543,14 @@ assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) { | |||
| 499 | 543 | } | |
| 500 | 544 | }; | |
| 501 | 545 | ||
| 546 | + /** | ||
| 547 | + * The deep strict non-equivalence assertion tests for any deep strict | ||
| 548 | + * inequality. | ||
| 549 | + * @param {any} actual | ||
| 550 | + * @param {any} expected | ||
| 551 | + * @param {string | Error} [message] | ||
| 552 | + * @returns {void} | ||
| 553 | + */ | ||
| 502 | 554 | assert.notDeepStrictEqual = notDeepStrictEqual; | |
| 503 | 555 | function notDeepStrictEqual(actual, expected, message) { | |
| 504 | 556 | if (arguments.length < 2) { | |
@@ -516,6 +568,13 @@ function notDeepStrictEqual(actual, expected, message) { | |||
| 516 | 568 | } | |
| 517 | 569 | } | |
| 518 | 570 | ||
| 571 | + /** | ||
| 572 | + * The strict equivalence assertion tests a strict equality relation. | ||
| 573 | + * @param {any} actual | ||
| 574 | + * @param {any} expected | ||
| 575 | + * @param {string | Error} [message] | ||
| 576 | + * @returns {void} | ||
| 577 | + */ | ||
| 519 | 578 | assert.strictEqual = function strictEqual(actual, expected, message) { | |
| 520 | 579 | if (arguments.length < 2) { | |
| 521 | 580 | throw new ERR_MISSING_ARGS('actual', 'expected'); | |
@@ -531,6 +590,13 @@ assert.strictEqual = function strictEqual(actual, expected, message) { | |||
| 531 | 590 | } | |
| 532 | 591 | }; | |
| 533 | 592 | ||
| 593 | + /** | ||
| 594 | + * The strict non-equivalence assertion tests for any strict inequality. | ||
| 595 | + * @param {any} actual | ||
| 596 | + * @param {any} expected | ||
| 597 | + * @param {string | Error} [message] | ||
| 598 | + * @returns {void} | ||
| 599 | + */ | ||
| 534 | 600 | assert.notStrictEqual = function notStrictEqual(actual, expected, message) { | |
| 535 | 601 | if (arguments.length < 2) { | |
| 536 | 602 | throw new ERR_MISSING_ARGS('actual', 'expected'); | |
@@ -839,22 +905,51 @@ function expectsNoError(stackStartFn, actual, error, message) { | |||
| 839 | 905 | throw actual; | |
| 840 | 906 | } | |
| 841 | 907 | ||
| 908 | + /** | ||
| 909 | + * Expects the function `promiseFn` to throw an error. | ||
| 910 | + * @param {() => any} promiseFn | ||
| 911 | + * @param {...any} [args] | ||
| 912 | + * @returns {void} | ||
| 913 | + */ | ||
| 842 | 914 | assert.throws = function throws(promiseFn, ...args) { | |
| 843 | 915 | expectsError(throws, getActual(promiseFn), ...args); | |
| 844 | 916 | }; | |
| 845 | 917 | ||
| 918 | + /** | ||
| 919 | + * Expects `promiseFn` function or its value to reject. | ||
| 920 | + * @param {() => Promise<any>} promiseFn | ||
| 921 | + * @param {...any} [args] | ||
| 922 | + * @returns {Promise<void>} | ||
| 923 | + */ | ||
| 846 | 924 | assert.rejects = async function rejects(promiseFn, ...args) { | |
| 847 | 925 | expectsError(rejects, await waitForActual(promiseFn), ...args); | |
| 848 | 926 | }; | |
| 849 | 927 | ||
| 928 | + /** | ||
| 929 | + * Asserts that the function `fn` does not throw an error. | ||
| 930 | + * @param {() => any} fn | ||
| 931 | + * @param {...any} [args] | ||
| 932 | + * @returns {void} | ||
| 933 | + */ | ||
| 850 | 934 | assert.doesNotThrow = function doesNotThrow(fn, ...args) { | |
| 851 | 935 | expectsNoError(doesNotThrow, getActual(fn), ...args); | |
| 852 | 936 | }; | |
| 853 | 937 | ||
| 938 | + /** | ||
| 939 | + * Expects `fn` or its value to not reject. | ||
| 940 | + * @param {() => Promise<any>} fn | ||
| 941 | + * @param {...any} [args] | ||
| 942 | + * @returns {Promise<void>} | ||
| 943 | + */ | ||
| 854 | 944 | assert.doesNotReject = async function doesNotReject(fn, ...args) { | |
| 855 | 945 | expectsNoError(doesNotReject, await waitForActual(fn), ...args); | |
| 856 | 946 | }; | |
| 857 | 947 | ||
| 948 | + /** | ||
| 949 | + * Throws `value` if the value is not `null` or `undefined`. | ||
| 950 | + * @param {any} err | ||
| 951 | + * @returns {void} | ||
| 952 | + */ | ||
| 858 | 953 | assert.ifError = function ifError(err) { | |
| 859 | 954 | if (err !== null && err !== undefined) { | |
| 860 | 955 | let message = 'ifError got unwanted exception: '; | |
@@ -939,24 +1034,44 @@ function internalMatch(string, regexp, message, fn) { | |||
| 939 | 1034 | } | |
| 940 | 1035 | } | |
| 941 | 1036 | ||
| 1037 | + /** | ||
| 1038 | + * Expects the `string` input to match the regular expression. | ||
| 1039 | + * @param {string} string | ||
| 1040 | + * @param {RegExp} regexp | ||
| 1041 | + * @param {string | Error} [message] | ||
| 1042 | + * @returns {void} | ||
| 1043 | + */ | ||
| 942 | 1044 | assert.match = function match(string, regexp, message) { | |
| 943 | 1045 | internalMatch(string, regexp, message, match); | |
| 944 | 1046 | }; | |
| 945 | 1047 | ||
| 1048 | + /** | ||
| 1049 | + * Expects the `string` input not to match the regular expression. | ||
| 1050 | + * @param {string} string | ||
| 1051 | + * @param {RegExp} regexp | ||
| 1052 | + * @param {string | Error} [message] | ||
| 1053 | + * @returns {void} | ||
| 1054 | + */ | ||
| 946 | 1055 | assert.doesNotMatch = function doesNotMatch(string, regexp, message) { | |
| 947 | 1056 | internalMatch(string, regexp, message, doesNotMatch); | |
| 948 | 1057 | }; | |
| 949 | 1058 | ||
| 950 | 1059 | assert.CallTracker = CallTracker; | |
| 951 | 1060 | ||
| 952 | - // Expose a strict only variant of assert | ||
| 1061 | + /** | ||
| 1062 | + * Expose a strict only variant of assert. | ||
| 1063 | + * @param {...any} args | ||
| 1064 | + * @returns {void} | ||
| 1065 | + */ | ||
| 953 | 1066 | function strict(...args) { | |
| 954 | 1067 | innerOk(strict, args.length, ...args); | |
| 955 | 1068 | } | |
| 1069 | + | ||
| 956 | 1070 | assert.strict = ObjectAssign(strict, assert, { | |
| 957 | 1071 | equal: assert.strictEqual, | |
| 958 | 1072 | deepEqual: assert.deepStrictEqual, | |
| 959 | 1073 | notEqual: assert.notStrictEqual, | |
| 960 | 1074 | notDeepEqual: assert.notDeepStrictEqual | |
| 961 | 1075 | }); | |
| 1076 | + | ||
| 962 | 1077 | assert.strict.strict = assert.strict; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments