Skip to content

Commit

Permalink
Add test for Option passed to wrong routines (#1729)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed May 22, 2022
1 parent 4094e22 commit 1bab84c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/command.option-misuse.test.js
@@ -0,0 +1,22 @@
const { Command, Option } = require('../');

// It is a reasonable and easy mistake to pass Option to .option(). Detect this
// and offer advice.

const expectedMessage = 'To add an Option object use addOption() instead of option() or requiredOption()';

test('when pass Option to .option() then throw', () => {
const program = new Command();

expect(() => {
program.option(new Option('-d, debug'));
}).toThrow(expectedMessage);
});

test('when pass Option to .requiredOption() then throw', () => {
const program = new Command();

expect(() => {
program.requiredOption(new Option('-d, debug'));
}).toThrow(expectedMessage);
});

0 comments on commit 1bab84c

Please sign in to comment.