diff --git a/lib/internal/process/promises.js b/lib/internal/process/promises.js index ee54594ba3c..ab833776070 100644 --- a/lib/internal/process/promises.js +++ b/lib/internal/process/promises.js @@ -199,10 +199,12 @@ function processPromiseRejections() { } case kDefaultUnhandledRejections: { const handled = process.emit('unhandledRejection', reason, promise); - if (!handled) emitUnhandledRejectionWarning(uid, reason); - if (!deprecationWarned) { - emitDeprecationWarning(); - deprecationWarned = true; + if (!handled) { + emitUnhandledRejectionWarning(uid, reason); + if (!deprecationWarned) { + emitDeprecationWarning(); + deprecationWarned = true; + } } break; } diff --git a/test/parallel/test-promise-handled-rejection-no-warning.js b/test/parallel/test-promise-handled-rejection-no-warning.js new file mode 100644 index 00000000000..14b06affb73 --- /dev/null +++ b/test/parallel/test-promise-handled-rejection-no-warning.js @@ -0,0 +1,8 @@ +'use strict'; +const common = require('../common'); + +// This test verifies that DEP0018 does not occur when rejections are handled. +common.disableCrashOnUnhandledRejection(); +process.on('warning', common.mustNotCall()); +process.on('unhandledRejection', common.mustCall()); +Promise.reject(new Error());