Skip to content
Myr

command.unknownCommand.test.js

This file

Path

tests/command.unknownCommand.test.js

64 lines · 1.6 KiB · JavaScript

Last changed by

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

History of this file

Take it

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

lines 1–20why, one step back
1const commander = require('../');
23describe('unknownOption', () => {4 // Optional. Use internal knowledge to suppress output to keep test output clean.5 let consoleErrorSpy;67 beforeAll(() => {8 consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => { });9 });1011 afterEach(() => {12 consoleErrorSpy.mockClear();13 });1415 afterAll(() => {16 consoleErrorSpy.mockRestore();17 });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 back
21 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–29why, one step back
25 });
2627 test('when unknown command but action handler then no error', () => {28 const program = new commander.Command();29 program

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

lines 30–32why, one step back
30 .exitOverride()
31 .command('sub');32 program

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

line 33why, one step back
33 .action(() => { });

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

lines 34–36why, one step back
34 expect(() => {
35 program.parse('node test.js unknown'.split(' '));36 }).not.toThrow();

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

lines 37–41why, one step back
37 });
3839 test('when unknown command but listener then no error', () => {40 const program = new commander.Command();41 program

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

lines 42–44why, one step back
42 .exitOverride()
43 .command('sub');44 program

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

line 45why, one step back
45 .on('command:*', () => { });

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

lines 46–48why, one step back
46 expect(() => {
47 program.parse('node test.js unknown'.split(' '));48 }).not.toThrow();

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

lines 49–64why, one step back
49 });
5051 test('when unknown command then error', () => {52 const program = new commander.Command();53 program54 .exitOverride()55 .command('sub');56 let caughtErr;57 try {58 program.parse('node test.js unknown'.split(' '));59 } catch (err) {60 caughtErr = err;61 }62 expect(caughtErr.code).toBe('commander.unknownCommand');63 });64});