• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --unhandled-rejections=warn
2'use strict';
3
4const common = require('../common');
5const assert = require('assert');
6
7// Verify that ignoring unhandled rejection works fine and that no warning is
8// logged.
9
10new Promise(() => {
11  throw new Error('One');
12});
13
14Promise.reject('test');
15
16function lookForMeInStackTrace() {
17  Promise.reject(new class ErrorLike {
18    constructor() {
19      Error.captureStackTrace(this);
20      this.message = 'ErrorLike';
21    }
22  }());
23}
24lookForMeInStackTrace();
25
26// Unhandled rejections trigger two warning per rejection. One is the rejection
27// reason and the other is a note where this warning is coming from.
28process.on('warning', common.mustCall((reason) => {
29  if (reason.message.includes('ErrorLike')) {
30    assert.match(reason.stack, /lookForMeInStackTrace/);
31  }
32}, 6));
33process.on('uncaughtException', common.mustNotCall('uncaughtException'));
34process.on('rejectionHandled', common.mustCall(3));
35
36process.on('unhandledRejection', (reason, promise) => {
37  // Handle promises but still warn!
38  promise.catch(() => {});
39});
40
41setTimeout(common.mustCall(), 2);
42