command.addHelpOption.test.js
This file
Path
tests/command.addHelpOption.test.js
53 lines · 1.5 KiB · JavaScript
Last changed by
Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
History of this fileTake it
Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
lines 1–10why, one step back1const { Command, Option } = require('../');23// More complete tests are in command.helpOption.test.js.45describe('addHelpOption', () => {6 let writeSpy;7 let writeErrorSpy;89 beforeAll(() => {10 // Optional. Suppress expected output to keep test output clean.Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 11–14why, one step back11 writeSpy = jest.spyOn(process.stdout, 'write').mockImplementation(() => {});12 writeErrorSpy = jest13 .spyOn(process.stderr, 'write')14 .mockImplementation(() => {});Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
lines 15–28why, one step back15 });1617 afterEach(() => {18 writeSpy.mockClear();19 writeErrorSpy.mockClear();20 });2122 afterAll(() => {23 writeSpy.mockRestore();24 writeErrorSpy.mockRestore();25 });2627 test('when addHelpOption has custom flags then custom short flag invokes help', () => {28 const program = new Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 29why, one step back29 program.exitOverride().addHelpOption(new Option('-c,--custom-help'));Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
lines 30–37why, one step back3031 expect(() => {32 program.parse(['-c'], { from: 'user' });33 }).toThrow('(outputHelp)');34 });3536 test('when addHelpOption has custom flags then custom long flag invokes help', () => {37 const program = new Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 38why, one step back38 program.exitOverride().addHelpOption(new Option('-c,--custom-help'));Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
lines 39–46why, one step back3940 expect(() => {41 program.parse(['--custom-help'], { from: 'user' });42 }).toThrow('(outputHelp)');43 });4445 test('when addHelpOption with hidden help option then help does not include help option', () => {46 const program = new Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 47–49why, one step back47 program.addHelpOption(48 new Option('-c,--custom-help', 'help help help').hideHelp(),49 );Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
lines 50–53why, one step back50 const helpInfo = program.helpInformation();51 expect(helpInfo).not.toMatch(/help/);52 });53});