Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add unhandled rejection guard #17275

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion test/addons-napi/test_promise/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const common = require('../../common');
const assert = require('assert');
const test_promise = require(`./build/${common.buildType}/test_promise`);

common.crashOnUnhandledRejection();

// A resolution
{
const expected_result = 42;
Expand Down Expand Up @@ -44,7 +46,14 @@ const test_promise = require(`./build/${common.buildType}/test_promise`);
}

assert.strictEqual(test_promise.isPromise(test_promise.createPromise()), true);
assert.strictEqual(test_promise.isPromise(Promise.reject(-1)), true);

const rejectPromise = Promise.reject(-1);
const expected_reason = -1;
assert.strictEqual(test_promise.isPromise(rejectPromise), true);
rejectPromise.catch((reason) => {
assert.strictEqual(reason, expected_reason);
});

assert.strictEqual(test_promise.isPromise(2.4), false);
assert.strictEqual(test_promise.isPromise('I promise!'), false);
assert.strictEqual(test_promise.isPromise(undefined), false);
Expand Down