help.visibleCommands.test.js
This file
Path
tests/help.visibleCommands.test.js
33 lines · 1.2 KiB · JavaScript
Last changed by
Fix syntactically incorrect command name (#1488)John Geebefore adoption7b6567e
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334const 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).
describe('visibleCommands', () => { test('when no subcommands then empty array', () => { const program = new commander.Command(); const helper = new commander.Help(); expect(helper.visibleCommands(program)).toEqual([]); });
test('when add command then visible (with help)', () => { const program = new commander.Command(); program .command('sub'); const helper = new commander.Help(); const visibleCommandNames = helper.visibleCommands(program).map(cmd => cmd.name()); expect(visibleCommandNames).toEqual(['sub', 'help']); });
test('when commands hidden then not visible', () => { const program = new commander.Command(); program .command('visible', 'desc') .command('invisible-executable', 'desc', { hidden: true }); program .command('invisible-action', { hidden: true }); const helper = new commander.Help(); const visibleCommandNames = helper.visibleCommands(program).map(cmd => cmd.name()); expect(visibleCommandNames).toEqual(['visible', 'help']); });});