Skip to content
Myr

command.createArgument.test.js

This file

Path

tests/command.createArgument.test.js

40 lines · 1.2 KiB · JavaScript

Last changed by

Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c

History of this file

Take it

Factory routine to create a new unattached argument (#1497)Sergei Vizelbefore adoption387b6fc

lines 1–6why, one step back
1const commander = require('../');
23class MyArgument extends commander.Argument {4 constructor(name, description) {5 super(name, description);6 this.myProperty = 'MyArgument';

Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c

line 7why, one step back
7 }

Factory routine to create a new unattached argument (#1497)Sergei Vizelbefore adoption387b6fc

lines 8–12why, one step back
8}
910class MyCommand extends commander.Command {11 createArgument(name, description) {12 return new MyArgument(name, description);

Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c

line 13why, one step back
13 }

Factory routine to create a new unattached argument (#1497)Sergei Vizelbefore adoption387b6fc

lines 14–40why, one step back
14
15 // 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});