command.option-misuse.test.js
This file
Path
tests/command.option-misuse.test.js
33 lines · 935 bytes · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334import { Command, Option } from '../index.js';import { test, describe } from 'node:test';import assert from 'node:assert/strict';
// It is a reasonable and easy mistake to pass Option to .option(). Detect this// and offer advice.
const expectedMessage = 'To add an Option object use addOption() instead of option() or requiredOption()';
describe('Command methods detect and explains misuse when incorrectly pass Option object', () => { test('when pass Option to .option() then throw', () => { const program = new Command();
assert.throws( () => { program.option(new Option('-d, debug')); }, { message: expectedMessage }, ); });
test('when pass Option to .requiredOption() then throw', () => { const program = new Command();
assert.throws( () => { program.requiredOption(new Option('-d, debug')); }, { message: expectedMessage }, ); });});