Skip to content
Myr

command.unknownCommand.test.js

This file

Path

tests/command.unknownCommand.test.js

81 lines · 2.2 KiB · JavaScript

Last changed by

Add showHelpAfterError (#1534)John Geebefore adoption082717f

History of this file

Take it

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

Update supported details for 7.x (#1419)John Geebefore adoption20cef03

lines 1–2why, one step back
1const commander = require('../');
2

Skip unknown options check if there is a better error to display (#1464)John Geebefore adoption4f78587

line 3why, one step back
3describe('unknownCommand', () => {

Update supported details for 7.x (#1419)John Geebefore adoption20cef03

lines 4–32why, one step back
4 // Optional. Use internal knowledge to suppress output to keep test output clean.
5 let writeErrorSpy;67 beforeAll(() => {8 writeErrorSpy = jest.spyOn(process.stderr, 'write').mockImplementation(() => { });9 });1011 afterEach(() => {12 writeErrorSpy.mockClear();13 });1415 afterAll(() => {16 writeErrorSpy.mockRestore();17 });1819 test('when unknown argument in simple program then no error', () => {20 const program = new commander.Command();21 program.exitOverride();22 expect(() => {23 program.parse('node test.js unknown'.split(' '));24 }).not.toThrow();25 });2627 test('when unknown command but action handler taking arg then no error', () => {28 const program = new commander.Command();29 program30 .exitOverride()31 .command('sub');32 program

More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9

line 33why, one step back
33 .argument('[args...]')

Update supported details for 7.x (#1419)John Geebefore adoption20cef03

lines 34–59why, one step back
34 .action(() => { });
35 expect(() => {36 program.parse('node test.js unknown'.split(' '));37 }).not.toThrow();38 });3940 test('when unknown command but listener then no error', () => {41 const program = new commander.Command();42 program43 .exitOverride()44 .command('sub');45 program46 .on('command:*', () => { });47 expect(() => {48 program.parse('node test.js unknown'.split(' '));49 }).not.toThrow();50 });5152 test('when unknown command then error', () => {53 const program = new commander.Command();54 program55 .exitOverride()56 .command('sub');57 let caughtErr;58 try {59 program.parse('node test.js unknown'.split(' '));

Skip unknown options check if there is a better error to display (#1464)John Geebefore adoption4f78587

lines 60–75why, one step back
60 } catch (err) {
61 caughtErr = err;62 }63 expect(caughtErr.code).toBe('commander.unknownCommand');64 });6566 test('when unknown command and unknown option then error is for unknown command', () => {67 // The unknown command is more useful since the option is for an unknown command (and might be68 // ok if the command had been correctly spelled, say).69 const program = new commander.Command();70 program71 .exitOverride()72 .command('sub');73 let caughtErr;74 try {75 program.parse('node test.js sbu --silly'.split(' '));

Update supported details for 7.x (#1419)John Geebefore adoption20cef03

lines 76–81why, one step back
76 } catch (err) {
77 caughtErr = err;78 }79 expect(caughtErr.code).toBe('commander.unknownCommand');80 });81});