From ca514aed05ed48563843d4e645163b37c05fc216 Mon Sep 17 00:00:00 2001 From: John Gee Date: Mon, 10 May 2021 11:01:07 +1200 Subject: [PATCH] Add test to cover exception from custom argument processing (#1515) --- tests/argument.custom-processing.test.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/argument.custom-processing.test.js b/tests/argument.custom-processing.test.js index 480fa73d6..509d9c111 100644 --- a/tests/argument.custom-processing.test.js +++ b/tests/argument.custom-processing.test.js @@ -142,3 +142,24 @@ test('when defined default value for required argument then throw', () => { program.argument('', 'float argument', 4); }).toThrow(); }); + +test('when custom processing for argument throws plain error then not CommanderError caught', () => { + function justSayNo(value) { + throw new Error('no no no'); + } + const program = new commander.Command(); + program + .exitOverride() + .argument('[n]', 'number', justSayNo) + .action(() => {}); + + let caughtErr; + try { + program.parse(['green'], { from: 'user' }); + } catch (err) { + caughtErr = err; + } + + expect(caughtErr).toBeInstanceOf(Error); + expect(caughtErr).not.toBeInstanceOf(commander.CommanderError); +});