8000 test: fix up N-API error test · nodejs/node@21f0577 · GitHub
[go: up one dir, main page]

Skip to content

Commit 21f0577

Browse files
Gabriel SchulhofMylesBorins
authored andcommitted
test: fix up N-API error test
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>
1 parent 17e4c8b commit 21f0577

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

test/addons-napi/test_error/test.js

Lines changed: 10 additions & 3 deletions
< 634A td data-grid-cell-id="diff-911596b40a77ecda8fafaf2d7114445137b46f4ae26e99bd993663dfa81817b9-73-76-2" data-line-anchor="diff-911596b40a77ecda8fafaf2d7114445137b46f4ae26e99bd993663dfa81817b9R76" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell left-side">
testThrowArbitrary(true);
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,23 @@ assert.throws(() => {
6161
}, /^TypeError: type error$/);
6262

6363
function testThrowArbitrary(value) {
64-
assert.throws(() => {
65-
test_error.throwArbitrary(value);
66-
}, value);
64+
assert.throws(
65+
() => test_error.throwArbitrary(value),
66+
(err) => {
67+
assert.strictEqual(err, value);
68+
return true;
69+
});
6770
}
6871

6972
testThrowArbitrary(42);
7073
testThrowArbitrary({});
7174
testThrowArbitrary([]);
7275
testThrowArbitrary(Symbol('xyzzy'));
7376
77+
testThrowArbitrary('ball');
78+
testThrowArbitrary(undefined);
79+
testThrowArbitrary(null);
80+
testThrowArbitrary(NaN);
7481

7582
common.expectsError(
7683
() => test_error.throwErrorCode(),

0 commit comments

Comments
 (0)
0