command.usage.test.js
This file
Path
tests/command.usage.test.js
46 lines · 1.4 KiB · JavaScript
Last changed by
Parse rework for nested commands (#1149)John Geebefore adoption1345f98
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647const commander = require('../');
test('when default usage and check program help then starts with default usage', () => { const program = new commander.Command();
program.name('test'); const helpInformation = program.helpInformation();
expect(helpInformation).toMatch(new RegExp('^Usage: test \\[options\\]'));});
test('when custom usage and check program help then starts with custom usage', () => { const myUsage = 'custom'; const program = new commander.Command(); program .usage(myUsage);
program.name('test'); const helpInformation = program.helpInformation();
expect(helpInformation).toMatch(new RegExp(`^Usage: test ${myUsage}`));});
test('when default usage and check subcommand help then starts with default usage including program name', () => { const program = new commander.Command(); const subCommand = program .command('info');
program.name('test'); const helpInformation = subCommand.helpInformation();
expect(helpInformation).toMatch(new RegExp('^Usage: test info \\[options\\]'));});
test('when custom usage and check subcommand help then starts with custom usage including program name', () => { const myUsage = 'custom'; const program = new commander.Command(); const subCommand = program .command('info') .usage(myUsage);
program.name('test'); const helpInformation = subCommand.helpInformation();
expect(helpInformation).toMatch(new RegExp(`^Usage: test info ${myUsage}`));});