Skip to content

Commit 9711075

Browse files
committed
test: add unhandled rejection guard
Add an unhandled rejection function in addons-napi/test_promise/test.js. Also, add a rejection handler to catch the unhandled rejection after introducing the guard and test the reason code.
1 parent 4ca4db0 commit 9711075

File tree

1 file changed

+10
-1
lines changed
  • test/addons-napi/test_promise

1 file changed

+10
-1
lines changed

test/addons-napi/test_promise/test.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const common = require('../../common');
77
const assert = require('assert');
88
const test_promise = require(`./build/${common.buildType}/test_promise`);
99

10+
common.crashOnUnhandledRejection();
11+
1012
// A resolution
1113
{
1214
const expected_result = 42;
@@ -44,7 +46,14 @@ const test_promise = require(`./build/${common.buildType}/test_promise`);
4446
}
4547

4648
assert.strictEqual(test_promise.isPromise(test_promise.createPromise()), true);
47-
assert.strictEqual(test_promise.isPromise(Promise.reject(-1)), true);
49+
50+
const rejectPromise = Promise.reject(-1);
51+
const expected_reason = -1;
52+
assert.strictEqual(test_promise.isPromise(rejectPromise), true);
53+
rejectPromise.catch((reason) => {
54+
assert.strictEqual(reason, expected_reason);
55+
});
56+
4857
assert.strictEqual(test_promise.isPromise(2.4), false);
4958
assert.strictEqual(test_promise.isPromise('I promise!'), false);
5059
assert.strictEqual(test_promise.isPromise(undefined), false);

0 commit comments

Comments
 (0)