forked from tj/commander.js
/
createCommand.test.js
36 lines (32 loc) · 1.03 KB
/
createCommand.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
const commander = require('../');
test('when createCommand then unattached', () => {
const program = new commander.Command();
const cmd = program.createCommand();
expect(program.commands.length).toBe(0);
expect(cmd.parent).toBeFalsy(); // (actually null, but use weaker test for unattached)
});
test('when subclass overrides createCommand then subcommand is subclass', () => {
class MyClass extends commander.Command {
constructor(name) {
super();
this.myProperty = 'myClass';
};
createCommand(name) {
return new MyClass(name);
};
};
const program = new MyClass();
const sub = program.command('sub');
expect(sub.myProperty).toEqual('myClass');
});
test('when override createCommand then subcommand is custom', () => {
function createCustom(name) {
const cmd = new commander.Command();
cmd.myProperty = 'custom';
return cmd;
}
const program = createCustom();
program.createCommand = createCustom;
const sub = program.command('sub');
expect(sub.myProperty).toEqual('custom');
});