Skip to content
Myr

command.unknownCommand.test.js

This file

Path

tests/command.unknownCommand.test.js

72 lines · 2.1 KiB · JavaScript

Last changed by

Disallow excess arguments (#2223)John Geebefore adoption58c28eb

History of this file

Take it

The walk stopped after 200 commits: lines older than cc2db5b point at it.

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

lines 1–7why, one step back
1const commander = require('../');
23describe('unknownCommand', () => {4 // Optional. Use internal knowledge to suppress output to keep test output clean.5 let writeErrorSpy;67 beforeAll(() => {

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 8–10why, one step back
8 writeErrorSpy = jest
9 .spyOn(process.stderr, 'write')10 .mockImplementation(() => {});

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

lines 11–20why, one step back
11 });
1213 afterEach(() => {14 writeErrorSpy.mockClear();15 });1617 afterAll(() => {18 writeErrorSpy.mockRestore();19 });20

Disallow excess arguments (#2223)John Geebefore adoption58c28eb

line 21why, one step back
21 test('when unknown argument in simple program then error', () => {

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

lines 22–25why, one step back
22 const program = new commander.Command();
23 program.exitOverride();24 expect(() => {25 program.parse('node test.js unknown'.split(' '));

Disallow excess arguments (#2223)John Geebefore adoption58c28eb

line 26why, one step back
26 }).toThrow();

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

lines 27–30why, one step back
27 });
2829 test('when unknown command but action handler taking arg then no error', () => {30 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 31–32why, one step back
31 program.exitOverride().command('sub');
32 program.argument('[args...]').action(() => {});

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

lines 33–39why, one step back
33 expect(() => {
34 program.parse('node test.js unknown'.split(' '));35 }).not.toThrow();36 });3738 test('when unknown command but listener then no error', () => {39 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 40–41why, one step back
40 program.exitOverride().command('sub');
41 program.on('command:*', () => {});

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

lines 42–48why, one step back
42 expect(() => {
43 program.parse('node test.js unknown'.split(' '));44 }).not.toThrow();45 });4647 test('when unknown command then error', () => {48 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 49why, one step back
49 program.exitOverride().command('sub');

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

lines 50–62why, one step back
50 let caughtErr;
51 try {52 program.parse('node test.js unknown'.split(' '));53 } catch (err) {54 caughtErr = err;55 }56 expect(caughtErr.code).toBe('commander.unknownCommand');57 });5859 test('when unknown command and unknown option then error is for unknown command', () => {60 // The unknown command is more useful since the option is for an unknown command (and might be61 // ok if the command had been correctly spelled, say).62 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 63why, one step back
63 program.exitOverride().command('sub');

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

lines 64–72why, one step back
64 let caughtErr;
65 try {66 program.parse('node test.js sbu --silly'.split(' '));67 } catch (err) {68 caughtErr = err;69 }70 expect(caughtErr.code).toBe('commander.unknownCommand');71 });72});