Skip to content

Commit

Permalink
Add test that addCommand requires name
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed Jan 21, 2020
1 parent 099f4f7 commit 3809648
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion tests/command.addCommand.test.js
Expand Up @@ -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();
});

0 comments on commit 3809648

Please sign in to comment.