Skip to content

Commit 502add9

Browse files
lib: move checkIsPromise function to private method in Assert class
1 parent dab3d01 commit 502add9

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

lib/assert.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,11 @@ class Assert {
345345
// Return a rejected promise if `promiseFn` throws synchronously.
346346
resultPromise = promiseFn();
347347
// Fail in case no promise is returned.
348-
if (!checkIsPromise(resultPromise)) {
348+
if (!this.#checkIsPromise(resultPromise)) {
349349
throw new ERR_INVALID_RETURN_VALUE('instance of Promise',
350350
'promiseFn', resultPromise);
351351
}
352-
} else if (checkIsPromise(promiseFn)) {
352+
} else if (this.#checkIsPromise(promiseFn)) {
353353
resultPromise = promiseFn;
354354
} else {
355355
throw new ERR_INVALID_ARG_TYPE(
@@ -374,6 +374,16 @@ class Assert {
374374
return NO_EXCEPTION_SENTINEL;
375375
}
376376

377+
#checkIsPromise(obj) {
378+
// Accept native ES6 promises and promises that are implemented in a similar
379+
// way. Do not accept thenables that use a function as `obj` and that have no
380+
// `catch` handler.
381+
return isPromise(obj) ||
382+
(obj !== null && typeof obj === 'object' &&
383+
typeof obj.then === 'function' &&
384+
typeof obj.catch === 'function');
385+
}
386+
377387
/**
378388
* Pure assertion tests whether a value is truthy, as determined
379389
* by !!value.
@@ -808,16 +818,6 @@ class Comparison {
808818
}
809819
}
810820

811-
function checkIsPromise(obj) {
812-
// Accept native ES6 promises and promises that are implemented in a similar
813-
// way. Do not accept thenables that use a function as `obj` and that have no
814-
// `catch` handler.
815-
return isPromise(obj) ||
816-
(obj !== null && typeof obj === 'object' &&
817-
typeof obj.then === 'function' &&
818-
typeof obj.catch === 'function');
819-
}
820-
821821
function hasMatchingError(actual, expected) {
822822
if (typeof expected !== 'function') {
823823
if (isRegExp(expected)) {

0 commit comments

Comments
 (0)