help.optionDescription.test.js
This file
Path
tests/help.optionDescription.test.js
69 lines · 3.2 KiB · JavaScript
Last changed by
Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
History of this fileTake it
Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912
lines 1–19why, one step back1const 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('optionDescription', () => {7 test('when option has no description then empty string', () => {8 const option = new commander.Option('-a');9 const helper = new commander.Help();10 expect(helper.optionDescription(option)).toEqual('');11 });1213 test('when option has description then return description', () => {14 const description = 'description';15 const option = new commander.Option('-a', description);16 const helper = new commander.Help();17 expect(helper.optionDescription(option)).toEqual(description);18 });19Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
line 20why, one step back20 test('when boolean option has default value true then return description and default value', () => {Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912
line 21why, one step back21 const description = 'description';Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
line 22why, one step back22 const option = new commander.Option('-a', description).default(true);Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912
line 23why, one step back23 const helper = new commander.Help();Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
line 24why, one step back24 expect(helper.optionDescription(option)).toEqual('description (default: true)');Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912
lines 25–26why, one step back25 });26Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
lines 27–46why, one step back27 test('when boolean option has default value string then return description without default', () => {28 const description = 'description';29 const option = new commander.Option('-a', description).default('foo');30 const helper = new commander.Help();31 expect(helper.optionDescription(option)).toEqual('description');32 });3334 test('when optional option has preset value then return description and default value', () => {35 const description = 'description';36 const option = new commander.Option('--aa [value]', description).preset('abc');37 const helper = new commander.Help();38 expect(helper.optionDescription(option)).toEqual('description (preset: "abc")');39 });4041 test('when boolean option has preset value then return description without default', () => {42 const description = 'description';43 const option = new commander.Option('--bb', description).preset('abc');44 const helper = new commander.Help();45 expect(helper.optionDescription(option)).toEqual('description');46 });Add .env method to Option for consulting environment variable for option value (#1587)John Geebefore adoption8571a75
lines 47–53why, one step back47 test('when option has env then return description and env name', () => {48 const description = 'description';49 const option = new commander.Option('-a', description).env('ENV');50 const helper = new commander.Help();51 expect(helper.optionDescription(option)).toEqual('description (env: ENV)');52 });53Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912
lines 54–56why, one step back54 test('when option has default value description then return description and custom default description', () => {55 const description = 'description';56 const defaultValueDescription = 'custom';Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
line 57why, one step back57 const option = new commander.Option('-a <value>', description).default('default value', defaultValueDescription);Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912
lines 58–64why, one step back58 const helper = new commander.Help();59 expect(helper.optionDescription(option)).toEqual(`description (default: ${defaultValueDescription})`);60 });6162 test('when option has choices then return description and choices', () => {63 const description = 'description';64 const choices = ['one', 'two'];Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
line 65why, one step back65 const option = new commander.Option('-a <value>', description).choices(choices);Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912
lines 66–69why, one step back66 const helper = new commander.Help();67 expect(helper.optionDescription(option)).toEqual('description (choices: "one", "two")');68 });69});