help.commandTerm.test.js
This file
Path
tests/help.commandTerm.test.js
43 lines · 1.7 KiB · JavaScript
Last changed by
More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041424344const 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>'); });});