Skip to content

Commit

Permalink
Refactor "subcommands + no action + unknown option when allowed" test
Browse files Browse the repository at this point in the history
- Make the test name more precise
- Move the test to a place where it fits better
  • Loading branch information
aweebit committed Aug 11, 2023
1 parent 026b36b commit 7dcbbea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 16 additions & 0 deletions tests/command.allowUnknownOption.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,20 @@ describe('allowUnknownOption', () => {
const result = program.parseOptions(['-m']);
expect(result).toEqual({ operands: ['-m'], unknown: [] });
});

test('when specify only unknown program option and allowUnknownOption and program has subcommands and no action handler then display help', () => {
const program = new commander.Command();
program
.configureHelp({ formatHelp: () => '' })
.exitOverride()
.allowUnknownOption()
.command('foo');
let caughtErr;
try {
program.parse(['--unknown'], { from: 'user' });
} catch (err) {
caughtErr = err;
}
expect(caughtErr.code).toEqual('commander.help');
});
});
16 changes: 0 additions & 16 deletions tests/command.helpCommand.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,6 @@ describe('help command listed in helpInformation', () => {
expect(helpInformation).toMatch(/help \[command\]/);
});

test('when program has subcommands and specify only unknown option then display help', () => {
const program = new commander.Command();
program
.configureHelp({ formatHelp: () => '' })
.exitOverride()
.allowUnknownOption()
.command('foo');
let caughtErr;
try {
program.parse(['--unknown'], { from: 'user' });
} catch (err) {
caughtErr = err;
}
expect(caughtErr.code).toEqual('commander.help');
});

test('when program has subcommands and suppress help command then no help command', () => {
const program = new commander.Command();
program.addHelpCommand(false);
Expand Down

0 comments on commit 7dcbbea

Please sign in to comment.