Skip to content

Commit

Permalink
test: stricten readline keypress failure test condition
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
BridgeAR authored and MylesBorins committed Jan 16, 2020
1 parent 49364b0 commit 4244080
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions test/parallel/test-readline-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,15 +561,20 @@ function isWarned(emitter) {
{ input: fi, output: fi, terminal: true }
);
const keys = [];
const err = new Error('bad thing happened');
fi.on('keypress', function(key) {
keys.push(key);
if (key === 'X') {
throw new Error('bad thing happened');
throw err;
}
});
try {
fi.emit('data', 'fooX');
} catch { }
assert.throws(
() => fi.emit('data', 'fooX'),
(e) => {
assert.strictEqual(e, err);
return true;
}
);
fi.emit('data', 'bar');
assert.strictEqual(keys.join(''), 'fooXbar');
rli.close();
Expand Down

0 comments on commit 4244080

Please sign in to comment.