/
command.createArgument.test.js
40 lines (34 loc) · 1.18 KB
/
command.createArgument.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
const commander = require('../');
class MyArgument extends commander.Argument {
constructor(name, description) {
super(name, description);
this.myProperty = 'MyArgument';
};
}
class MyCommand extends commander.Command {
createArgument(name, description) {
return new MyArgument(name, description);
};
// createCommand for testing .command('sub <file>')
createCommand(name) {
return new MyCommand(name);
}
}
test('when override createArgument then used for argument()', () => {
const program = new MyCommand();
program.argument('<file>');
expect(program._args.length).toEqual(1);
expect(program._args[0].myProperty).toEqual('MyArgument');
});
test('when override createArgument then used for arguments()', () => {
const program = new MyCommand();
program.arguments('<file>');
expect(program._args.length).toEqual(1);
expect(program._args[0].myProperty).toEqual('MyArgument');
});
test('when override createArgument and createCommand then used for argument of command()', () => {
const program = new MyCommand();
const sub = program.command('sub <file>');
expect(sub._args.length).toEqual(1);
expect(sub._args[0].myProperty).toEqual('MyArgument');
});