help.commandTerm.test.js
This file
Path
tests/help.commandTerm.test.js
42 lines · 1.7 KiB · JavaScript
Last changed by
Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334353637383940414243const commander = require('../');
// These are tests of the Help class, not of the Command help.// There is some overlap with the higher level Command tests (which predate Help).
// subcommandTerm does not currently respect helpOption or ignore hidden options, so not testing those.describe('subcommandTerm', () => { test('when plain command then returns name', () => { const command = new commander.Command('program'); const helper = new commander.Help(); expect(helper.subcommandTerm(command)).toEqual('program'); });
test('when command has alias then returns name|alias', () => { const command = new commander.Command('program').alias('alias'); const helper = new commander.Help(); expect(helper.subcommandTerm(command)).toEqual('program|alias'); });
test('when command has options then returns name [options]', () => { const command = new commander.Command('program').option('-a,--all'); const helper = new commander.Help(); expect(helper.subcommandTerm(command)).toEqual('program [options]'); });
test('when command has <argument> then returns name <argument>', () => { const command = new commander.Command('program').argument('<argument>'); const helper = new commander.Help(); expect(helper.subcommandTerm(command)).toEqual('program <argument>'); });
test('when command has everything then returns name|alias [options] <argument>', () => { const command = new commander.Command('program') .alias('alias') .option('-a,--all') .argument('<argument>'); const helper = new commander.Help(); expect(helper.subcommandTerm(command)).toEqual( 'program|alias [options] <argument>', ); });});