Skip to content
Myr

command.createOption.test.js

This file

Path

tests/command.createOption.test.js

42 lines · 1.3 KiB · JavaScript

Last changed by

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

History of this file

Take it

Feature createOption (#1380)John Geebefore adoptionb1d984b

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

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

line 7why, one step back
7 }

Feature createOption (#1380)John Geebefore adoptionb1d984b

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

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

line 13why, one step back
13 }

Feature createOption (#1380)John Geebefore adoptionb1d984b

lines 14–42why, one step back
14}
1516test('when override createOption then used for option()', () => {17 const program = new MyCommand();18 program.option('-a, --alpha');19 expect(program.options.length).toEqual(1);20 expect(program.options[0].myProperty).toEqual('MyOption');21});2223test('when override createOption then used for requiredOption()', () => {24 const program = new MyCommand();25 program.requiredOption('-a, --alpha');26 expect(program.options.length).toEqual(1);27 expect(program.options[0].myProperty).toEqual('MyOption');28});2930test('when override createOption then used for version()', () => {31 const program = new MyCommand();32 program.version('1.2.3');33 expect(program.options.length).toEqual(1);34 expect(program.options[0].myProperty).toEqual('MyOption');35});3637test('when override createOption then used for help option in visibleOptions', () => {38 const program = new MyCommand();39 const visibleOptions = program.createHelp().visibleOptions(program);40 expect(visibleOptions.length).toEqual(1);41 expect(visibleOptions[0].myProperty).toEqual('MyOption');42});