Skip to content

Commit 4244080

Browse files
BridgeARMylesBorins
authored andcommitted
test: stricten readline keypress failure test condition
This verifies that the thrown error is the expected one. That was not tested before. PR-URL: #31300 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 49364b0 commit 4244080

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

test/parallel/test-readline-interface.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,15 +561,20 @@ function isWarned(emitter) {
561561
{ input: fi, output: fi, terminal: true }
562562
);
563563
const keys = [];
564+
const err = new Error('bad thing happened');
564565
fi.on('keypress', function(key) {
565566
keys.push(key);
566567
if (key === 'X') {
567-
throw new Error('bad thing happened');
568+
throw err;
568569
}
569570
});
570-
try {
571-
fi.emit('data', 'fooX');
572-
} catch { }
571+
assert.throws(
572+
() => fi.emit('data', 'fooX'),
573+
(e) => {
574+
assert.strictEqual(e, err);
575+
return true;
576+
}
577+
);
573578
fi.emit('data', 'bar');
574579
assert.strictEqual(keys.join(''), 'fooXbar');
575580
rli.close();

0 commit comments

Comments
 (0)