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 <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Yongsheng Zhang <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
BridgeAR authored and codebytere committed Mar 17, 2020
1 parent 20f857f commit 20167fe
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 @@ -501,15 +501,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 20167fe

Please sign in to comment.