Skip to content
Myr

argument.choices.test.js

This file

Path

tests/argument.choices.test.js

57 lines · 2.1 KiB · JavaScript

Last changed by

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

History of this file

Take 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 back
1import * 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 back
5

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 6–17why, one step back
6describe('Argument.choices()', () => {
7 test('when command argument in choices then argument set', () => {8 const program = createTestCommand();9 let shade;10 program11 .addArgument(new commander.Argument('<shade>').choices(['red', 'blue']))12 .action((shadeParam) => {13 shade = shadeParam;14 });15 program.parse(['red'], { from: 'user' });16 assert.equal(shade, 'red');17 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 18why, one step back
18

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 19–27why, one step back
19 test('when command argument is not in choices then error', () => {
20 // Lightweight check, more detailed testing of behaviour in command.exitOverride.test.js21 const program = createTestCommand();22 program.addArgument(23 new commander.Argument('<shade>').choices(['red', 'blue']),24 );25 assert.throws(() => {26 program.parse(['orange'], { from: 'user' });27 });

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 28why, one step back
28 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 29–30why, one step back
29});
30

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

line 31why, one step back
31describe('Argument.choices() parameter is treated as readonly, per TypeScript declaration', () => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 32–36why, one step back
32 test('when choices called then parameter does not change', () => {
33 // Unlikely this could break, but check the API we are declaring in TypeScript.34 const original = ['red', 'blue', 'green'];35 const param = original.slice();36 new commander.Argument('<shade>').choices(param);

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 37why, one step back
37 assert.deepEqual(param, original);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 38–44why, one step back
38 });
3940 test('when choices called and argChoices later changed then parameter does not change', () => {41 const original = ['red', 'blue', 'green'];42 const param = original.slice();43 const argument = new commander.Argument('<shade>').choices(param);44 argument.argChoices.push('purple');

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 45why, one step back
45 assert.deepEqual(param, original);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 46–48why, one step back
46 });
4748 test('when choices called and parameter changed the choices does not change', () => {

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 49why, one step back
49 const program = createTestCommand();

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 50why, one step back
50 const param = ['red', 'blue'];

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 51why, one step back
51 program.addArgument(new commander.Argument('<shade>').choices(param));

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 52why, one step back
52 param.push('orange');

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 53why, one step back
53 assert.throws(() => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 54why, one step back
54 program.parse(['orange'], { from: 'user' });

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 55why, one step back
55 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 56–57why, one step back
56 });
57});