Skip to content
Myr

command.onCommand.test.js

This file

Path

tests/command.onCommand.test.js

38 lines · 1.3 KiB · JavaScript

Last changed by

Not known.

History of this file

Take it

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

Update dependencies (#1524)John Geebefore adoption0b0fbbe

lines 1–38why, one step back
1const 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();10 program11 .command('sub')12 .action(() => {});13 program.on('command:sub', mockListener);14 program.parse(['sub'], { from: 'user' });15 expect(mockListener).toHaveBeenCalled();16 });1718 test('when no action handler for subcommand then still emit command:subcommand', () => {19 const mockListener = jest.fn();20 const program = new commander.Command();21 program22 .command('sub');23 program.on('command:sub', mockListener);24 program.parse(['sub'], { from: 'user' });25 expect(mockListener).toHaveBeenCalled();26 });2728 test('when subcommand has argument then emit command:subcommand with argument', () => {29 const mockListener = jest.fn();30 const program = new commander.Command();31 program32 .command('sub <file>')33 .action(() => {});34 program.on('command:sub', mockListener);35 program.parse(['sub', 'file'], { from: 'user' });36 expect(mockListener).toHaveBeenCalledWith(['file'], []);37 });38});