Skip to content
Myr

createCommand.test.js

This file

Path

tests/createCommand.test.js

36 lines · 1.0 KiB · JavaScript

Last changed by

createCommand factory routine (#1191)John Geebefore adoption8c3dd6f

History of this file

Take it

createCommand factory routine (#1191)John Geebefore adoption8c3dd6f

lines 1–36why, one step back
1const 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';15 };1617 createCommand(name) {18 return new MyClass(name);19 };20 };21 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});