Skip to content

Commit

Permalink
Add test to cover exception from custom argument processing (#1515)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed May 9, 2021
1 parent 8b5599e commit ca514ae
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/argument.custom-processing.test.js
Expand Up @@ -142,3 +142,24 @@ test('when defined default value for required argument then throw', () => {
program.argument('<number>', '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);
});

0 comments on commit ca514ae

Please sign in to comment.