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.

PR-URL: #17275
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
babygoat authored and MylesBorins committed Jan 8, 2018
1 parent d70e6dc commit 5cd08d3
Showing 1 changed file with 10 additions and 1 deletion.
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

0 comments on commit 5cd08d3

Please sign in to comment.