command.createArgument.test.js
This file
Path
tests/command.createArgument.test.js
44 lines · 1.4 KiB · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445import * as commander from '../index.js';import { test, describe } from 'node:test';import assert from 'node:assert/strict';
class MyArgument extends commander.Argument { constructor(name, description) { super(name, description); this.myProperty = 'MyArgument'; }}
class MyCommand extends commander.Command { createArgument(name, description) { return new MyArgument(name, description); }
// createCommand for testing .command('sub <file>') createCommand(name) { return new MyCommand(name); }}
describe('Command.createArgument() override in subclass', () => { test('when override createArgument then used for argument()', () => { const program = new MyCommand(); program.argument('<file>'); assert.equal(program.registeredArguments.length, 1); assert.equal(program.registeredArguments[0].myProperty, 'MyArgument'); });
test('when override createArgument then used for arguments()', () => { const program = new MyCommand(); program.arguments('<file>'); assert.equal(program.registeredArguments.length, 1); assert.equal(program.registeredArguments[0].myProperty, 'MyArgument'); });
test('when override createArgument and createCommand then used for argument of command()', () => { const program = new MyCommand(); const sub = program.command('sub <file>'); assert.equal(sub.registeredArguments.length, 1); assert.equal(sub.registeredArguments[0].myProperty, 'MyArgument'); });});