Skip to content

Commit e5e0a83

Browse files
lib: move checkIsPromise function to private method in Assert class
1 parent deadf90 commit e5e0a83

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
@@ -343,11 +343,11 @@ class Assert {
343343
// Return a rejected promise if `promiseFn` throws synchronously.
344344
resultPromise = promiseFn();
345345
// Fail in case no promise is returned.
346-
if (!checkIsPromise(resultPromise)) {
346+
if (!this.#checkIsPromise(resultPromise)) {
347347
throw new ERR_INVALID_RETURN_VALUE('instance of Promise',
348348
'promiseFn', resultPromise);
349349
}
350-
} else if (checkIsPromise(promiseFn)) {
350+
} else if (this.#checkIsPromise(promiseFn)) {
351351
resultPromise = promiseFn;
352352
} else {
353353
throw new ERR_INVALID_ARG_TYPE(
@@ -372,6 +372,16 @@ class Assert {
372372
return NO_EXCEPTION_SENTINEL;
373373
}
374374

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

1053-
function checkIsPromise(obj) {
1054-
// Accept native ES6 promises and promises that are implemented in a similar
1055-
// way. Do not accept thenables that use a function as `obj` and that have no
1056-
// `catch` handler.
1057-
return isPromise(obj) ||
1058-
(obj !== null && typeof obj === 'object' &&
1059-
typeof obj.then === 'function' &&
1060-
typeof obj.catch === 'function');
1061-
}
1062-
10631063
function hasMatchingError(actual, expected) {
10641064
if (typeof expected !== 'function') {
10651065
if (isRegExp(expected)) {

0 commit comments

Comments
 (0)