Skip to content
Myr

help.visibleOptions.test.js

This file

Path

tests/help.visibleOptions.test.js

70 lines · 2.8 KiB · JavaScript

Last changed by

Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912

History of this file

Take it

Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912

lines 1–70why, one step back
1const commander = require('../');
23// These are tests of the Help class, not of the Command help.4// There is some overlap with the higher level Command tests (which predate Help).56describe('visibleOptions', () => {7 test('when no options then just help visible', () => {8 const program = new commander.Command();9 const helper = new commander.Help();10 const visibleOptionNames = helper.visibleOptions(program).map(option => option.name());11 expect(visibleOptionNames).toEqual(['help']);12 });1314 test('when no options and no help option then empty array', () => {15 const program = new commander.Command();16 program.helpOption(false);17 const helper = new commander.Help();18 expect(helper.visibleOptions(program)).toEqual([]);19 });2021 test('when add option then visible (with help)', () => {22 const program = new commander.Command();23 program.option('-v,--visible');24 const helper = new commander.Help();25 const visibleOptionNames = helper.visibleOptions(program).map(option => option.name());26 expect(visibleOptionNames).toEqual(['visible', 'help']);27 });2829 test('when option hidden then not visible', () => {30 const program = new commander.Command();31 program32 .option('-v,--visible')33 .addOption(new commander.Option('--invisible').hideHelp());34 const helper = new commander.Help();35 const visibleOptionNames = helper.visibleOptions(program).map(option => option.name());36 expect(visibleOptionNames).toEqual(['visible', 'help']);37 });38});3940describe('implicit help', () => {41 test('when default then help term is -h, --help', () => {42 const program = new commander.Command();43 const helper = new commander.Help();44 const implicitHelp = helper.visibleOptions(program)[0];45 expect(helper.optionTerm(implicitHelp)).toEqual('-h, --help');46 });4748 test('when short flag obscured then help term is --help', () => {49 const program = new commander.Command();50 program.addOption(new commander.Option('-h, --huge').hideHelp());51 const helper = new commander.Help();52 const implicitHelp = helper.visibleOptions(program)[0];53 expect(helper.optionTerm(implicitHelp)).toEqual('--help');54 });5556 test('when long flag obscured then help term is --h', () => {57 const program = new commander.Command();58 program.addOption(new commander.Option('-H, --help').hideHelp());59 const helper = new commander.Help();60 const implicitHelp = helper.visibleOptions(program)[0];61 expect(helper.optionTerm(implicitHelp)).toEqual('-h');62 });6364 test('when help flags obscured then implicit help hidden', () => {65 const program = new commander.Command();66 program.addOption(new commander.Option('-h, --help').hideHelp());67 const helper = new commander.Help();68 expect(helper.visibleOptions(program)).toEqual([]);69 });70});