-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
help.optionDescription.test.js
69 lines (60 loc) · 3.18 KB
/
help.optionDescription.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const commander = require('../');
// These are tests of the Help class, not of the Command help.
// There is some overlap with the higher level Command tests (which predate Help).
describe('optionDescription', () => {
test('when option has no description then empty string', () => {
const option = new commander.Option('-a');
const helper = new commander.Help();
expect(helper.optionDescription(option)).toEqual('');
});
test('when option has description then return description', () => {
const description = 'description';
const option = new commander.Option('-a', description);
const helper = new commander.Help();
expect(helper.optionDescription(option)).toEqual(description);
});
test('when boolean option has default value true then return description and default value', () => {
const description = 'description';
const option = new commander.Option('-a', description).default(true);
const helper = new commander.Help();
expect(helper.optionDescription(option)).toEqual('description (default: true)');
});
test('when boolean option has default value string then return description without default', () => {
const description = 'description';
const option = new commander.Option('-a', description).default('foo');
const helper = new commander.Help();
expect(helper.optionDescription(option)).toEqual('description');
});
test('when optional option has preset value then return description and default value', () => {
const description = 'description';
const option = new commander.Option('--aa [value]', description).preset('abc');
const helper = new commander.Help();
expect(helper.optionDescription(option)).toEqual('description (preset: "abc")');
});
test('when boolean option has preset value then return description without default', () => {
const description = 'description';
const option = new commander.Option('--bb', description).preset('abc');
const helper = new commander.Help();
expect(helper.optionDescription(option)).toEqual('description');
});
test('when option has env then return description and env name', () => {
const description = 'description';
const option = new commander.Option('-a', description).env('ENV');
const helper = new commander.Help();
expect(helper.optionDescription(option)).toEqual('description (env: ENV)');
});
test('when option has default value description then return description and custom default description', () => {
const description = 'description';
const defaultValueDescription = 'custom';
const option = new commander.Option('-a <value>', description).default('default value', defaultValueDescription);
const helper = new commander.Help();
expect(helper.optionDescription(option)).toEqual(`description (default: ${defaultValueDescription})`);
});
test('when option has choices then return description and choices', () => {
const description = 'description';
const choices = ['one', 'two'];
const option = new commander.Option('-a <value>', description).choices(choices);
const helper = new commander.Help();
expect(helper.optionDescription(option)).toEqual('description (choices: "one", "two")');
});
});