-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw error when add option with clashing flags (#2055)
- Loading branch information
1 parent
d90e81e
commit b96af40
Showing
2 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const { Command, Option } = require('../'); | ||
|
||
describe('.option()', () => { | ||
test('when short option flag conflicts then throws', () => { | ||
expect(() => { | ||
const program = new Command(); | ||
program | ||
.option('-c, --cheese <type>', 'cheese type') | ||
.option('-c, --conflict'); | ||
}).toThrow('Cannot add option'); | ||
}); | ||
|
||
test('when long option flag conflicts then throws', () => { | ||
expect(() => { | ||
const program = new Command(); | ||
program | ||
.option('-c, --cheese <type>', 'cheese type') | ||
.option('-H, --cheese'); | ||
}).toThrow('Cannot add option'); | ||
}); | ||
|
||
test('when use help options separately then does not throw', () => { | ||
expect(() => { | ||
const program = new Command(); | ||
program | ||
.option('-h, --help', 'display help'); | ||
}).not.toThrow(); | ||
}); | ||
|
||
test('when reuse flags in subcommand then does not throw', () => { | ||
expect(() => { | ||
const program = new Command(); | ||
program | ||
.option('e, --example'); | ||
program.command('sub') | ||
.option('e, --example'); | ||
}).not.toThrow(); | ||
}); | ||
}); | ||
|
||
describe('.addOption()', () => { | ||
test('when short option flags conflicts then throws', () => { | ||
expect(() => { | ||
const program = new Command(); | ||
program | ||
.option('-c, --cheese <type>', 'cheese type') | ||
.addOption(new Option('-c, --conflict')); | ||
}).toThrow('Cannot add option'); | ||
}); | ||
|
||
test('when long option flags conflicts then throws', () => { | ||
expect(() => { | ||
const program = new Command(); | ||
program | ||
.option('-c, --cheese <type>', 'cheese type') | ||
.addOption(new Option('-H, --cheese')); | ||
}).toThrow('Cannot add option'); | ||
}); | ||
}); |