Skip to content
Myr

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 file

Take it

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

lines 1–2why, one step back
1const commander = require('../');
2

Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b

lines 3–4why, one step back
3describe('helpOption', () => {
4 let writeSpy;

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

line 5why, one step back
5

Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b

lines 6–65why, one step back
6 beforeAll(() => {
7 // Optional. Suppress normal output to keep test output clean.8 writeSpy = jest.spyOn(process.stdout, 'write').mockImplementation(() => { });9 });1011 afterEach(() => {12 writeSpy.mockClear();13 });1415 afterAll(() => {16 writeSpy.mockRestore();17 });1819 test('when helpOption has custom flags then custom short flag invokes help', () => {20 const program = new commander.Command();21 program22 .exitOverride()23 .helpOption('-c,--custom-help', 'custom help output');24 expect(() => {25 program.parse(['-c'], { from: 'user' });26 }).toThrow('(outputHelp)');27 });2829 test('when helpOption has custom flags then custom long flag invokes help', () => {30 const program = new commander.Command();31 program32 .exitOverride()33 .helpOption('-c,--custom-help', 'custom help output');34 expect(() => {35 program.parse(['--custom-help'], { from: 'user' });36 }).toThrow('(outputHelp)');37 });3839 test('when helpOption has just custom short flag then custom short flag invokes help', () => {40 const program = new commander.Command();41 program42 .exitOverride()43 .helpOption('-c', 'custom help output');44 expect(() => {45 program.parse(['-c'], { from: 'user' });46 }).toThrow('(outputHelp)');47 });4849 test('when helpOption has just custom long flag then custom long flag invokes help', () => {50 const program = new commander.Command();51 program52 .exitOverride()53 .helpOption('--custom-help', 'custom help output');54 expect(() => {55 program.parse(['--custom-help'], { from: 'user' });56 }).toThrow('(outputHelp)');57 });5859 test('when helpOption has custom description then helpInformation include custom description', () => {60 const program = new commander.Command();61 program62 .helpOption('-C,--custom-help', 'custom help output');63 const helpInformation = program.helpInformation();64 expect(helpInformation).toMatch(/-C,--custom-help +custom help output/);65 });

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

line 66why, one step back
66});