Skip to content
Myr

help.longestOptionTermLength.test.js

This file

Path

tests/help.longestOptionTermLength.test.js

30 lines · 1.2 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–30why, 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('longestOptionTermLength', () => {7 test('when no option then returns zero', () => {8 const program = new commander.Command();9 program.helpOption(false);10 const helper = new commander.Help();11 expect(helper.longestOptionTermLength(program, helper)).toEqual(0);12 });1314 test('when just implicit help option returns length of help flags', () => {15 const program = new commander.Command();16 const helper = new commander.Help();17 expect(helper.longestOptionTermLength(program, helper)).toEqual('-h, --help'.length);18 });1920 test('when multiple option then returns longest length', () => {21 const longestOptionFlags = '-l, --longest <value>';22 const program = new commander.Command();23 program24 .option('--before', 'optional description of flags')25 .option(longestOptionFlags)26 .option('--after');27 const helper = new commander.Help();28 expect(helper.longestOptionTermLength(program, helper)).toEqual(longestOptionFlags.length);29 });30});