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 fileTake it
123456789101112131415161718192021222324252627282930313233343536373839const commander = require('../');
// The action handler used to be implemented using command events and listeners.// Now, this is mostly just for backwards compatibility.
describe(".command('*')", () => { test('when action handler for subcommand then emit command:subcommand', () => { const mockListener = jest.fn(); const program = new commander.Command(); program .command('sub') .action(() => {}); program.on('command:sub', mockListener); program.parse(['sub'], { from: 'user' }); expect(mockListener).toHaveBeenCalled(); });
test('when no action handler for subcommand then still emit command:subcommand', () => { const mockListener = jest.fn(); const program = new commander.Command(); program .command('sub'); program.on('command:sub', mockListener); program.parse(['sub'], { from: 'user' }); expect(mockListener).toHaveBeenCalled(); });
test('when subcommand has argument then emit command:subcommand with argument', () => { const mockListener = jest.fn(); const program = new commander.Command(); program .command('sub <file>') .action(() => {}); program.on('command:sub', mockListener); program.parse(['sub', 'file'], { from: 'user' }); expect(mockListener).toHaveBeenCalledWith(['file'], []); });});