From 20167fec5f2f2df2c336a1aa3f3119f154dc112d Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Fri, 10 Jan 2020 18:26:45 +0100 Subject: [PATCH] test: stricten readline keypress failure test condition This verifies that the thrown error is the expected one. That was not tested before. PR-URL: https://github.com/nodejs/node/pull/31300 Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Yongsheng Zhang Reviewed-By: Rich Trott --- test/parallel/test-readline-interface.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-readline-interface.js b/test/parallel/test-readline-interface.js index 08d3b363ddc4fa..2a4387bc07d602 100644 --- a/test/parallel/test-readline-interface.js +++ b/test/parallel/test-readline-interface.js @@ -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();