Skip to content
Myr

command.addHelpOption.test.js

This file

Path

tests/command.addHelpOption.test.js

54 lines · 1.6 KiB · JavaScript

Last changed by

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

History of this file

Take it

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

lines 1–54why, one step back
1const { 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.11 writeSpy = jest.spyOn(process.stdout, 'write').mockImplementation(() => { });12 writeErrorSpy = jest.spyOn(process.stderr, 'write').mockImplementation(() => { });13 });1415 afterEach(() => {16 writeSpy.mockClear();17 writeErrorSpy.mockClear();18 });1920 afterAll(() => {21 writeSpy.mockRestore();22 writeErrorSpy.mockRestore();23 });2425 test('when addHelpOption has custom flags then custom short flag invokes help', () => {26 const program = new Command();27 program28 .exitOverride()29 .addHelpOption(new Option('-c,--custom-help'));3031 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();38 program39 .exitOverride()40 .addHelpOption(new Option('-c,--custom-help'));4142 expect(() => {43 program.parse(['--custom-help'], { from: 'user' });44 }).toThrow('(outputHelp)');45 });4647 test('when addHelpOption with hidden help option then help does not include help option', () => {48 const program = new Command();49 program50 .addHelpOption(new Option('-c,--custom-help', 'help help help').hideHelp());51 const helpInfo = program.helpInformation();52 expect(helpInfo).not.toMatch(/help/);53 });54});