command.createArgument.test.js
This file
Path
tests/command.createArgument.test.js
40 lines · 1.3 KiB · JavaScript
Last changed by
Merge remote-tracking branch 'origin/develop' into release/12.xJohn Geebefore adoption9afbabd
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041const 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.registeredArguments.length).toEqual(1); expect(program.registeredArguments[0].myProperty).toEqual('MyArgument');});
test('when override createArgument then used for arguments()', () => { const program = new MyCommand(); program.arguments('<file>'); expect(program.registeredArguments.length).toEqual(1); expect(program.registeredArguments[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.registeredArguments.length).toEqual(1); expect(sub.registeredArguments[0].myProperty).toEqual('MyArgument');});