command.unknownCommand.test.js
This file
Path
tests/command.unknownCommand.test.js
65 lines · 1.6 KiB · JavaScript
Last changed by
Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
History of this fileTake it
Parse rework for nested commands (#1149)John Geebefore adoption1345f98
lines 1–4why, one step back1const commander = require('../');23describe('unknownOption', () => {4 // Optional. Use internal knowledge to suppress output to keep test output clean.configure output (#1387)John Geebefore adoptioned7f13e
line 5why, one step back5 let writeErrorSpy;Parse rework for nested commands (#1149)John Geebefore adoption1345f98
lines 6–7why, one step back67 beforeAll(() => {configure output (#1387)John Geebefore adoptioned7f13e
line 8why, one step back8 writeErrorSpy = jest.spyOn(process.stderr, 'write').mockImplementation(() => { });Parse rework for nested commands (#1149)John Geebefore adoption1345f98
lines 9–11why, one step back9 });1011 afterEach(() => {configure output (#1387)John Geebefore adoptioned7f13e
line 12why, one step back12 writeErrorSpy.mockClear();Parse rework for nested commands (#1149)John Geebefore adoption1345f98
lines 13–15why, one step back13 });1415 afterAll(() => {configure output (#1387)John Geebefore adoptioned7f13e
line 16why, one step back16 writeErrorSpy.mockRestore();Parse rework for nested commands (#1149)John Geebefore adoption1345f98
lines 17–20why, one step back17 });1819 test('when unknown argument in simple program then no error', () => {20 const program = new commander.Command();Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7
lines 21–24why, one step back21 program.exitOverride();22 expect(() => {23 program.parse('node test.js unknown'.split(' '));24 }).not.toThrow();Parse rework for nested commands (#1149)John Geebefore adoption1345f98
lines 25–26why, one step back25 });26Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 27why, one step back27 test('when unknown command but action handler taking arg then no error', () => {Parse rework for nested commands (#1149)John Geebefore adoption1345f98
lines 28–29why, one step back28 const program = new commander.Command();29 programUpdate dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7
lines 30–32why, one step back30 .exitOverride()31 .command('sub');32 programChange to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 33why, one step back33 .arguments('[args...]')Parse rework for nested commands (#1149)John Geebefore adoption1345f98
line 34why, one step back34 .action(() => { });Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7
lines 35–37why, one step back35 expect(() => {36 program.parse('node test.js unknown'.split(' '));37 }).not.toThrow();Parse rework for nested commands (#1149)John Geebefore adoption1345f98
lines 38–42why, one step back38 });3940 test('when unknown command but listener then no error', () => {41 const program = new commander.Command();42 programUpdate dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7
lines 43–45why, one step back43 .exitOverride()44 .command('sub');45 programParse rework for nested commands (#1149)John Geebefore adoption1345f98
line 46why, one step back46 .on('command:*', () => { });Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7
lines 47–49why, one step back47 expect(() => {48 program.parse('node test.js unknown'.split(' '));49 }).not.toThrow();Parse rework for nested commands (#1149)John Geebefore adoption1345f98
lines 50–65why, one step back50 });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(' '));60 } catch (err) {61 caughtErr = err;62 }63 expect(caughtErr.code).toBe('commander.unknownCommand');64 });65});