command.helpOption.test.js
This file
Path
tests/command.helpOption.test.js
22 lines · 871 bytes · JavaScript
Last changed by
Add override to allow throw instead of process.exit (#1040)John Geebefore adoption8df692e
History of this fileTake it
1234567891011121314151617181920212223const commander = require('../');
test('when helpOption has custom flags then custom flag invokes help', () => { // Optional. Suppress normal output to keep test output clean. const writeSpy = jest.spyOn(process.stdout, 'write').mockImplementation(() => { }); const program = new commander.Command(); program .exitOverride() .helpOption('--custom-help', 'custom help output'); expect(() => { program.parse(['node', 'test', '--custom-help']); }).toThrow('(outputHelp)'); writeSpy.mockClear();});
test('when helpOption has custom description then helpInformation include custom description', () => { const program = new commander.Command(); program .helpOption('-C,--custom-help', 'custom help output'); const helpInformation = program.helpInformation(); expect(helpInformation).toMatch(/-C,--custom-help +custom help output/);});