Skip to content

Commit

Permalink
test: add unhandled rejection guard
Browse files Browse the repository at this point in the history
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.

Backport-PR-URL: #19447
PR-URL: #17275
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
babygoat authored and MylesBorins committed Apr 16, 2018
1 parent e54b58c commit 86ddd03
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion test/addons-napi/test_promise/test.js
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

0 comments on commit 86ddd03

Please sign in to comment.