summaryrefslogtreecommitdiff
path: root/test/parallel/test-promises-warning-on-unhandled-rejection.js
diff options
context:
space:
mode:
authorMadara Uchiha <me@madara.ninja>2017-11-20 14:22:37 -0500
committerRefael Ackermann <refack@gmail.com>2017-11-22 17:33:52 -0500
commit13db29b2f7f0970c16228790f755262b3617f31e (patch)
treedcaa453067d22803df424683be9ab8fcfa0e52e2 /test/parallel/test-promises-warning-on-unhandled-rejection.js
parentc6b7052bb714d167b16fb6db56bd3977ecddee90 (diff)
downloadandroid-node-v8-13db29b2f7f0970c16228790f755262b3617f31e.tar.gz
android-node-v8-13db29b2f7f0970c16228790f755262b3617f31e.tar.bz2
android-node-v8-13db29b2f7f0970c16228790f755262b3617f31e.zip
process: improve unhandled rejection message
PR-URL: https://github.com/nodejs/node/pull/17158 Refs: https://github.com/nodejs/node/pull/16768 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-promises-warning-on-unhandled-rejection.js')
-rw-r--r--test/parallel/test-promises-warning-on-unhandled-rejection.js37
1 files changed, 31 insertions, 6 deletions
diff --git a/test/parallel/test-promises-warning-on-unhandled-rejection.js b/test/parallel/test-promises-warning-on-unhandled-rejection.js
index 10f95162a0..3ac7d8698b 100644
--- a/test/parallel/test-promises-warning-on-unhandled-rejection.js
+++ b/test/parallel/test-promises-warning-on-unhandled-rejection.js
@@ -12,18 +12,43 @@ let b = 0;
process.on('warning', common.mustCall((warning) => {
switch (b++) {
case 0:
- assert.strictEqual(warning.name, 'UnhandledPromiseRejectionWarning');
- assert(/Unhandled promise rejection/.test(warning.message));
+ // String rejection error displayed
+ assert.strictEqual(warning.message, 'This was rejected');
break;
case 1:
- assert.strictEqual(warning.name, 'DeprecationWarning');
+ // Warning about rejection not being handled (will be next tick)
+ assert.strictEqual(warning.name, 'UnhandledPromiseRejectionWarning');
+ assert(
+ /Unhandled promise rejection/.test(warning.message),
+ 'Expected warning message to contain "Unhandled promise rejection" ' +
+ 'but did not. Had "' + warning.message + '" instead.'
+ );
break;
case 2:
+ // One time deprecation warning, first unhandled rejection
+ assert.strictEqual(warning.name, 'DeprecationWarning');
+ break;
+ case 3:
+ // Number rejection error displayed. Note it's been stringified
+ assert.strictEqual(warning.message, '42');
+ break;
+ case 4:
+ // Unhandled rejection warning (won't be handled next tick)
+ assert.strictEqual(warning.name, 'UnhandledPromiseRejectionWarning');
+ assert(
+ /Unhandled promise rejection/.test(warning.message),
+ 'Expected warning message to contain "Unhandled promise rejection" ' +
+ 'but did not. Had "' + warning.message + '" instead.'
+ );
+ break;
+ case 5:
+ // Rejection handled asynchronously.
assert.strictEqual(warning.name, 'PromiseRejectionHandledWarning');
assert(/Promise rejection was handled asynchronously/
.test(warning.message));
}
-}, 3));
+}, 6));
-const p = Promise.reject('This was rejected');
-setImmediate(common.mustCall(() => p.catch(() => {})));
+const p = Promise.reject('This was rejected'); // Reject with a string
+setImmediate(common.mustCall(() => p.catch(() => { })));
+Promise.reject(42); // Reject with a number