Skip to content

Commit

Permalink
test: fix up N-API error test
Browse files Browse the repository at this point in the history
Replace assert.throws() with an explicit try/catch in order to catch
the thrown value and be able to compare it strictly to an expected
value.

Re: #20428 (comment)

PR-URL: #20487
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
Gabriel Schulhof authored and MylesBorins committed May 8, 2018
1 parent 5248cd7 commit 6966c04
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions test/addons-napi/test_error/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,23 @@ assert.throws(() => {
}, /^TypeError: type error$/);

function testThrowArbitrary(value) {
assert.throws(() => {
test_error.throwArbitrary(value);
}, value);
assert.throws(
() => test_error.throwArbitrary(value),
(err) => {
assert.strictEqual(err, value);
return true;
});
}

testThrowArbitrary(42);
testThrowArbitrary({});
testThrowArbitrary([]);
testThrowArbitrary(Symbol('xyzzy'));
testThrowArbitrary(true);
testThrowArbitrary('ball');
testThrowArbitrary(undefined);
testThrowArbitrary(null);
testThrowArbitrary(NaN);

common.expectsError(
() => test_error.throwErrorCode(),
Expand Down

0 comments on commit 6966c04

Please sign in to comment.