options.choices.test.js
This file
Path
tests/options.choices.test.js
56 lines · 2.1 KiB · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
The walk stopped after 200 commits: lines older than 471ec40 point at it.
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
lines 1–4why, one step back1import * as commander from '../index.js';2import { createTestCommand } from './testHelpers.js';3import { test, describe } from 'node:test';4import assert from 'node:assert/strict';Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 5why, one step back5Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 6–13why, one step back6describe('Option.choices()', () => {7 test('when option argument in choices then option set', () => {8 const program = new commander.Command();9 program.addOption(10 new commander.Option('--colour <shade>').choices(['red', 'blue']),11 );12 program.parse(['--colour', 'red'], { from: 'user' });13 assert.equal(program.opts().colour, 'red');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 14why, one step back14 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 15why, one step back15Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 16–17why, one step back16 test('when option argument is not in choices then error', () => {17 // Lightweight check, more detailed testing of behaviour in command.exitOverride.test.jsSwitch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 18why, one step back18 const program = createTestCommand();Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 19–21why, one step back19 program.addOption(20 new commander.Option('--colour <shade>').choices(['red', 'blue']),21 );Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 22why, one step back22 assert.throws(() => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 23why, one step back23 program.parse(['--colour', 'orange'], { from: 'user' });Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 24–53why, one step back24 });25 });2627 describe('choices parameter is treated as readonly, per TypeScript declaration', () => {28 test('when choices called then parameter does not change', () => {29 // Unlikely this could break, but check the API we are declaring in TypeScript.30 const original = ['red', 'blue', 'green'];31 const param = original.slice();32 new commander.Option('--colour <shade>').choices(param);33 assert.deepEqual(param, original);34 });3536 test('when choices called and argChoices later changed then parameter does not change', () => {37 const original = ['red', 'blue', 'green'];38 const param = original.slice();39 const option = new commander.Option('--colour <shade>').choices(param);40 option.argChoices.push('purple');41 assert.deepEqual(param, original);42 });4344 test('when choices called and parameter changed the choices does not change', () => {45 const program = createTestCommand();46 const param = ['red', 'blue'];47 program.addOption(48 new commander.Option('--colour <shade>').choices(param),49 );50 param.push('orange');51 assert.throws(() => {52 program.parse(['--colour', 'orange'], { from: 'user' });53 });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 54why, one step back54 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 55–56why, one step back55 });56});