Skip to content

Commit 1bab84c

Browse files
authoredMay 22, 2022
Add test for Option passed to wrong routines (#1729)
1 parent 4094e22 commit 1bab84c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
 

‎tests/command.option-misuse.test.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { Command, Option } = require('../');
2+
3+
// It is a reasonable and easy mistake to pass Option to .option(). Detect this
4+
// and offer advice.
5+
6+
const expectedMessage = 'To add an Option object use addOption() instead of option() or requiredOption()';
7+
8+
test('when pass Option to .option() then throw', () => {
9+
const program = new Command();
10+
11+
expect(() => {
12+
program.option(new Option('-d, debug'));
13+
}).toThrow(expectedMessage);
14+
});
15+
16+
test('when pass Option to .requiredOption() then throw', () => {
17+
const program = new Command();
18+
19+
expect(() => {
20+
program.requiredOption(new Option('-d, debug'));
21+
}).toThrow(expectedMessage);
22+
});

0 commit comments

Comments
 (0)
Please sign in to comment.