Skip to content
Myr

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 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–13why, one step back
6describe('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 back
14 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 15why, one step back
15

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

lines 16–17why, one step back
16 test('when option argument is not in choices then error', () => {
17 // Lightweight check, more detailed testing of behaviour in command.exitOverride.test.js

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

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

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

lines 19–21why, one step back
19 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 back
22 assert.throws(() => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 23why, one step back
23 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 back
24 });
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 back
54 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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