summaryrefslogtreecommitdiff
path: root/lib/assert.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-09-08 02:30:07 +0200
committerRuben Bridgewater <ruben@bridgewater.de>2018-09-11 23:45:07 +0200
commitb5430d782d1c00ecdc421ad28b4f6c5ff62ba972 (patch)
treeb4bb8637e2dbab8bc0455799ba2301346486623a /lib/assert.js
parente4dd213516afdff64063682e0d0d46c58499a9f3 (diff)
downloadandroid-node-v8-b5430d782d1c00ecdc421ad28b4f6c5ff62ba972.tar.gz
android-node-v8-b5430d782d1c00ecdc421ad28b4f6c5ff62ba972.tar.bz2
android-node-v8-b5430d782d1c00ecdc421ad28b4f6c5ff62ba972.zip
assert: align argument names
This makes sure the documented argument names and the ones thrown in errors is aligned with the actual argument name. PR-URL: https://github.com/nodejs/node/pull/22760 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
Diffstat (limited to 'lib/assert.js')
-rw-r--r--lib/assert.js41
1 files changed, 21 insertions, 20 deletions
diff --git a/lib/assert.js b/lib/assert.js
index 555b38f39e..e336119d92 100644
--- a/lib/assert.js
+++ b/lib/assert.js
@@ -555,12 +555,12 @@ function expectedException(actual, expected, msg) {
return expected.call({}, actual) === true;
}
-function getActual(block) {
- if (typeof block !== 'function') {
- throw new ERR_INVALID_ARG_TYPE('block', 'Function', block);
+function getActual(fn) {
+ if (typeof fn !== 'function') {
+ throw new ERR_INVALID_ARG_TYPE('fn', 'Function', fn);
}
try {
- block();
+ fn();
} catch (e) {
return e;
}
@@ -577,20 +577,21 @@ function checkIsPromise(obj) {
typeof obj.catch === 'function';
}
-async function waitForActual(block) {
+async function waitForActual(promiseFn) {
let resultPromise;
- if (typeof block === 'function') {
- // Return a rejected promise if `block` throws synchronously.
- resultPromise = block();
+ if (typeof promiseFn === 'function') {
+ // Return a rejected promise if `promiseFn` throws synchronously.
+ resultPromise = promiseFn();
// Fail in case no promise is returned.
if (!checkIsPromise(resultPromise)) {
throw new ERR_INVALID_RETURN_VALUE('instance of Promise',
- 'block', resultPromise);
+ 'promiseFn', resultPromise);
}
- } else if (checkIsPromise(block)) {
- resultPromise = block;
+ } else if (checkIsPromise(promiseFn)) {
+ resultPromise = promiseFn;
} else {
- throw new ERR_INVALID_ARG_TYPE('block', ['Function', 'Promise'], block);
+ throw new ERR_INVALID_ARG_TYPE(
+ 'promiseFn', ['Function', 'Promise'], promiseFn);
}
try {
@@ -676,20 +677,20 @@ function expectsNoError(stackStartFn, actual, error, message) {
throw actual;
}
-assert.throws = function throws(block, ...args) {
- expectsError(throws, getActual(block), ...args);
+assert.throws = function throws(promiseFn, ...args) {
+ expectsError(throws, getActual(promiseFn), ...args);
};
-assert.rejects = async function rejects(block, ...args) {
- expectsError(rejects, await waitForActual(block), ...args);
+assert.rejects = async function rejects(promiseFn, ...args) {
+ expectsError(rejects, await waitForActual(promiseFn), ...args);
};
-assert.doesNotThrow = function doesNotThrow(block, ...args) {
- expectsNoError(doesNotThrow, getActual(block), ...args);
+assert.doesNotThrow = function doesNotThrow(fn, ...args) {
+ expectsNoError(doesNotThrow, getActual(fn), ...args);
};
-assert.doesNotReject = async function doesNotReject(block, ...args) {
- expectsNoError(doesNotReject, await waitForActual(block), ...args);
+assert.doesNotReject = async function doesNotReject(fn, ...args) {
+ expectsNoError(doesNotReject, await waitForActual(fn), ...args);
};
assert.ifError = function ifError(err) {