command.onCommand.test.js
This file
Path
tests/command.onCommand.test.js
33 lines · 1.3 KiB · JavaScript
Last changed by
Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
History of this fileTake it
The walk stopped after 200 commits: lines older than 78e335f point at it.
Fix minor typo (#1579)John Geebefore adoption78e335f
lines 1–9why, one step back1const commander = require('../');23// The action handler used to be implemented using command events and listeners.4// Now, this is mostly just for backwards compatibility.56describe(".command('*')", () => {7 test('when action handler for subcommand then emit command:subcommand', () => {8 const mockListener = jest.fn();9 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 10why, one step back10 program.command('sub').action(() => {});Fix minor typo (#1579)John Geebefore adoption78e335f
lines 11–18why, one step back11 program.on('command:sub', mockListener);12 program.parse(['sub'], { from: 'user' });13 expect(mockListener).toHaveBeenCalled();14 });1516 test('when no action handler for subcommand then still emit command:subcommand', () => {17 const mockListener = jest.fn();18 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 19why, one step back19 program.command('sub');Fix minor typo (#1579)John Geebefore adoption78e335f
lines 20–27why, one step back20 program.on('command:sub', mockListener);21 program.parse(['sub'], { from: 'user' });22 expect(mockListener).toHaveBeenCalled();23 });2425 test('when subcommand has argument then emit command:subcommand with argument', () => {26 const mockListener = jest.fn();27 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 28why, one step back28 program.command('sub <file>').action(() => {});Fix minor typo (#1579)John Geebefore adoption78e335f
lines 29–33why, one step back29 program.on('command:sub', mockListener);30 program.parse(['sub', 'file'], { from: 'user' });31 expect(mockListener).toHaveBeenCalledWith(['file'], []);32 });33});