Skip to content

Commit 20167fe

Browse files
BridgeARcodebytere
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 <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 20f857f commit 20167fe

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

test/parallel/test-readline-interface.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -501,15 +501,20 @@ function isWarned(emitter) {
501501
{ input: fi, output: fi, terminal: true }
502502
);
503503
const keys = [];
504+
const err = new Error('bad thing happened');
504505
fi.on('keypress', function(key) {
505506
keys.push(key);
506507
if (key === 'X') {
507-
throw new Error('bad thing happened');
508+
throw err;
508509
}
509510
});
510-
try {
511-
fi.emit('data', 'fooX');
512-
} catch { }
511+
assert.throws(
512+
() => fi.emit('data', 'fooX'),
513+
(e) => {
514+
assert.strictEqual(e, err);
515+
return true;
516+
}
517+
);
513518
fi.emit('data', 'bar');
514519
assert.strictEqual(keys.join(''), 'fooXbar');
515520
rli.close();

0 commit comments

Comments
 (0)