Skip to content

Commit

Permalink
Add tests that help command robust against modified help option flags
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed Apr 16, 2023
1 parent 0a27547 commit cb7de18
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/command.helpCommand.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,41 @@ describe('help command processed on correct command', () => {
program.parse('node test.js help'.split(' '));
}).toThrow('program');
});

test('when no long help flag then "help sub" works', () => {
const program = new commander.Command();
program.exitOverride();
program.helpOption('-H');
const sub = program.command('sub');
// Patch help for easy way to check called.
sub.help = () => { throw new Error('sub help'); };
expect(() => {
program.parse(['help', 'sub'], { from: 'user' });
}).toThrow('sub help');
});

test('when no help options in sub then "help sub" works', () => {
const program = new commander.Command();
program.exitOverride();
const sub = program.command('sub')
.helpOption(false);
// Patch help for easy way to check called.
sub.help = () => { throw new Error('sub help'); };
expect(() => {
program.parse(['help', 'sub'], { from: 'user' });
}).toThrow('sub help');
});

test('when different help options in sub then "help sub" works', () => {
const program = new commander.Command();
program.exitOverride();
const sub = program.command('sub');
program.helpOption('-h, --help');
sub.helpOption('-a, --assist');
// Patch help for easy way to check called.
sub.help = () => { throw new Error('sub help'); };
expect(() => {
program.parse(['help', 'sub'], { from: 'user' });
}).toThrow('sub help');
});
});

0 comments on commit cb7de18

Please sign in to comment.