• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --unhandled-rejections=throw
2'use strict';
3
4const common = require('../common');
5const Countdown = require('../common/countdown');
6const assert = require('assert');
7
8common.disableCrashOnUnhandledRejection();
9
10// Verify that the unhandledRejection handler prevents triggering
11// uncaught exceptions
12
13const err1 = new Error('One');
14
15const errors = [err1, null];
16
17const ref = new Promise(() => {
18  throw err1;
19});
20// Explicitly reject `null`.
21Promise.reject(null);
22
23process.on('warning', common.mustNotCall('warning'));
24process.on('rejectionHandled', common.mustNotCall('rejectionHandled'));
25process.on('exit', assert.strictEqual.bind(null, 0));
26process.on('uncaughtException', common.mustNotCall('uncaughtException'));
27
28const timer = setTimeout(() => console.log(ref), 1000);
29
30const counter = new Countdown(2, () => {
31  clearTimeout(timer);
32});
33
34process.on('unhandledRejection', common.mustCall((err) => {
35  counter.dec();
36  const knownError = errors.shift();
37  assert.deepStrictEqual(err, knownError);
38}, 2));
39