diff --git a/index.js b/index.js index da13b0557..d5e6868b5 100644 --- a/index.js +++ b/index.js @@ -216,7 +216,7 @@ Command.prototype.command = function(nameAndArgs, actionOptsOrExecDesc, execOpts */ Command.prototype.addCommand = function(cmd) { - if (!cmd._name) throw Error('error: addCommand name is not specified for command'); + if (!cmd._name) throw new Error('Command passed to .AddCommand must have a name'); this.commands.push(cmd); cmd.parent = this; diff --git a/tests/command.addCommand.test.js b/tests/command.addCommand.test.js index 688818953..d77e96562 100644 --- a/tests/command.addCommand.test.js +++ b/tests/command.addCommand.test.js @@ -35,9 +35,17 @@ test('when commands added using .addCommand and .command then internals similar' case 'boolean': case 'number': case 'undefined': - // Compare vaues in a way that will make some sense in test failure message. + // Compare vaues in a way that will be readable in test failure message. expect(`${key}:${cmd1[key]}`).toEqual(`${key}:${cmd2[key]}`); break; } } }); + +test('when command without name passed to .addCommand then throw', () => { + const program = new commander.Command(); + const cmd = new commander.Command(); + expect(() => { + program.addCommand(cmd); + }).toThrow(); +});