-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathcommand.addHelpOption.test.js
53 lines (43 loc) · 1.54 KB
/
command.addHelpOption.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const { Command, Option } = require('../');
// More complete tests are in command.helpOption.test.js.
describe('addHelpOption', () => {
let writeSpy;
let writeErrorSpy;
beforeAll(() => {
// Optional. Suppress expected output to keep test output clean.
writeSpy = jest.spyOn(process.stdout, 'write').mockImplementation(() => {});
writeErrorSpy = jest
.spyOn(process.stderr, 'write')
.mockImplementation(() => {});
});
afterEach(() => {
writeSpy.mockClear();
writeErrorSpy.mockClear();
});
afterAll(() => {
writeSpy.mockRestore();
writeErrorSpy.mockRestore();
});
test('when addHelpOption has custom flags then custom short flag invokes help', () => {
const program = new Command();
program.exitOverride().addHelpOption(new Option('-c,--custom-help'));
expect(() => {
program.parse(['-c'], { from: 'user' });
}).toThrow('(outputHelp)');
});
test('when addHelpOption has custom flags then custom long flag invokes help', () => {
const program = new Command();
program.exitOverride().addHelpOption(new Option('-c,--custom-help'));
expect(() => {
program.parse(['--custom-help'], { from: 'user' });
}).toThrow('(outputHelp)');
});
test('when addHelpOption with hidden help option then help does not include help option', () => {
const program = new Command();
program.addHelpOption(
new Option('-c,--custom-help', 'help help help').hideHelp(),
);
const helpInfo = program.helpInformation();
expect(helpInfo).not.toMatch(/help/);
});
});