command.createArgument.test.js
This file
Path
tests/command.createArgument.test.js
40 lines · 1.2 KiB · JavaScript
Last changed by
Factory routine to create a new unattached argument (#1497)Sergei Vizelbefore adoption387b6fc
History of this fileTake it
Factory routine to create a new unattached argument (#1497)Sergei Vizelbefore adoption387b6fc
lines 1–40why, one step back1const commander = require('../');23class MyArgument extends commander.Argument {4 constructor(name, description) {5 super(name, description);6 this.myProperty = 'MyArgument';7 };8}910class MyCommand extends commander.Command {11 createArgument(name, description) {12 return new MyArgument(name, description);13 };1415 // createCommand for testing .command('sub <file>')16 createCommand(name) {17 return new MyCommand(name);18 }19}2021test('when override createArgument then used for argument()', () => {22 const program = new MyCommand();23 program.argument('<file>');24 expect(program._args.length).toEqual(1);25 expect(program._args[0].myProperty).toEqual('MyArgument');26});2728test('when override createArgument then used for arguments()', () => {29 const program = new MyCommand();30 program.arguments('<file>');31 expect(program._args.length).toEqual(1);32 expect(program._args[0].myProperty).toEqual('MyArgument');33});3435test('when override createArgument and createCommand then used for argument of command()', () => {36 const program = new MyCommand();37 const sub = program.command('sub <file>');38 expect(sub._args.length).toEqual(1);39 expect(sub._args[0].myProperty).toEqual('MyArgument');40});