2016-04-28 10:11:09 +02:00
|
|
|
// Flags: --no-warnings
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Test that warnings are emitted when a Promise experiences an uncaught
|
|
|
|
// rejection, and then again if the rejection is handled later on.
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
let b = 0;
|
2016-04-28 10:11:09 +02:00
|
|
|
|
|
|
|
process.on('warning', common.mustCall((warning) => {
|
|
|
|
switch (b++) {
|
|
|
|
case 0:
|
|
|
|
assert.strictEqual(warning.name, 'UnhandledPromiseRejectionWarning');
|
|
|
|
assert(/Unhandled promise rejection/.test(warning.message));
|
|
|
|
break;
|
|
|
|
case 1:
|
2016-08-22 06:16:40 +02:00
|
|
|
assert.strictEqual(warning.name, 'DeprecationWarning');
|
|
|
|
break;
|
|
|
|
case 2:
|
2016-04-28 10:11:09 +02:00
|
|
|
assert.strictEqual(warning.name, 'PromiseRejectionHandledWarning');
|
|
|
|
assert(/Promise rejection was handled asynchronously/
|
|
|
|
.test(warning.message));
|
|
|
|
}
|
2016-08-22 06:16:40 +02:00
|
|
|
}, 3));
|
2016-04-28 10:11:09 +02:00
|
|
|
|
|
|
|
const p = Promise.reject('This was rejected');
|
2017-03-24 17:46:44 +01:00
|
|
|
setImmediate(common.mustCall(() => p.catch(common.noop)));
|