createCommand.test.js
This file
Path
tests/createCommand.test.js
36 lines · 1.0 KiB · JavaScript
Last changed by
Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
History of this fileTake it
createCommand factory routine (#1191)John Geebefore adoption8c3dd6f
lines 1–14why, one step back1const commander = require('../');23test('when createCommand then unattached', () => {4 const program = new commander.Command();5 const cmd = program.createCommand();6 expect(program.commands.length).toBe(0);7 expect(cmd.parent).toBeFalsy(); // (actually null, but use weaker test for unattached)8});910test('when subclass overrides createCommand then subcommand is subclass', () => {11 class MyClass extends commander.Command {12 constructor(name) {13 super();14 this.myProperty = 'myClass';Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
line 15why, one step back15 }createCommand factory routine (#1191)John Geebefore adoption8c3dd6f
lines 16–18why, one step back1617 createCommand(name) {18 return new MyClass(name);Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
lines 19–20why, one step back19 }20 }createCommand factory routine (#1191)John Geebefore adoption8c3dd6f
lines 21–36why, one step back21 const program = new MyClass();22 const sub = program.command('sub');23 expect(sub.myProperty).toEqual('myClass');24});2526test('when override createCommand then subcommand is custom', () => {27 function createCustom(name) {28 const cmd = new commander.Command();29 cmd.myProperty = 'custom';30 return cmd;31 }32 const program = createCustom();33 program.createCommand = createCustom;34 const sub = program.command('sub');35 expect(sub.myProperty).toEqual('custom');36});