command.helpOption.test.js
This file
Path
tests/command.helpOption.test.js
66 lines · 2.0 KiB · JavaScript
Last changed by
Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667const commander = require('../');
describe('helpOption', () => { let writeSpy;
beforeAll(() => { // Optional. Suppress normal output to keep test output clean. writeSpy = jest.spyOn(process.stdout, 'write').mockImplementation(() => { }); });
afterEach(() => { writeSpy.mockClear(); });
afterAll(() => { writeSpy.mockRestore(); });
test('when helpOption has custom flags then custom short flag invokes help', () => { const program = new commander.Command(); program .exitOverride() .helpOption('-c,--custom-help', 'custom help output'); expect(() => { program.parse(['-c'], { from: 'user' }); }).toThrow('(outputHelp)'); });
test('when helpOption has custom flags then custom long flag invokes help', () => { const program = new commander.Command(); program .exitOverride() .helpOption('-c,--custom-help', 'custom help output'); expect(() => { program.parse(['--custom-help'], { from: 'user' }); }).toThrow('(outputHelp)'); });
test('when helpOption has just custom short flag then custom short flag invokes help', () => { const program = new commander.Command(); program .exitOverride() .helpOption('-c', 'custom help output'); expect(() => { program.parse(['-c'], { from: 'user' }); }).toThrow('(outputHelp)'); });
test('when helpOption has just custom long flag then custom long flag invokes help', () => { const program = new commander.Command(); program .exitOverride() .helpOption('--custom-help', 'custom help output'); expect(() => { program.parse(['--custom-help'], { from: 'user' }); }).toThrow('(outputHelp)'); });
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/); });});