command.alias.test.js
This file
Path
tests/command.alias.test.js
75 lines · 2.2 KiB · JavaScript
Last changed by
Add support for multiple aliases (#1236)John Geebefore adoption28e8d3f
History of this fileTake it
Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4
lines 1–14why, one step back1const commander = require('../');23// Running alias commands is tested in command.executableSubcommand.lookup.test.js4// Test various other behaviours for .alias56test('when command has alias then appears in help', () => {7 const program = new commander.Command();8 program9 .command('info [thing]')10 .alias('i');11 const helpInformation = program.helpInformation();12 expect(helpInformation).toMatch('info|i');13});14Add support for multiple aliases (#1236)John Geebefore adoption28e8d3f
line 15why, one step back15test('when command has aliases added separately then only first appears in help', () => {Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4
line 16why, one step back16 const program = new commander.Command();Add support for multiple aliases (#1236)John Geebefore adoption28e8d3f
lines 17–35why, one step back17 program18 .command('list [thing]')19 .alias('ls')20 .alias('dir');21 const helpInformation = program.helpInformation();22 expect(helpInformation).toMatch('list|ls ');23});2425test('when command has aliases then only first appears in help', () => {26 const program = new commander.Command();27 program28 .command('list [thing]')29 .aliases(['ls', 'dir']);30 const helpInformation = program.helpInformation();31 expect(helpInformation).toMatch('list|ls ');32});3334test('when command name = alias then error', () => {35 const program = new commander.Command();Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4
lines 36–40why, one step back36 expect(() => {37 program38 .command('fail')39 .alias('fail');40 }).toThrow("Command alias can't be the same as its name");Add support for multiple aliases (#1236)John Geebefore adoption28e8d3f
lines 41–74why, one step back41});4243test('when use alias then action handler called', () => {44 const program = new commander.Command();45 const actionMock = jest.fn();46 program47 .command('list')48 .alias('ls')49 .action(actionMock);50 program.parse(['ls'], { from: 'user' });51 expect(actionMock).toHaveBeenCalled();52});5354test('when use second alias added separately then action handler called', () => {55 const program = new commander.Command();56 const actionMock = jest.fn();57 program58 .command('list')59 .alias('ls')60 .alias('dir')61 .action(actionMock);62 program.parse(['dir'], { from: 'user' });63 expect(actionMock).toHaveBeenCalled();64});6566test('when use second of aliases then action handler called', () => {67 const program = new commander.Command();68 const actionMock = jest.fn();69 program70 .command('list')71 .aliases(['ls', 'dir'])72 .action(actionMock);73 program.parse(['dir'], { from: 'user' });74 expect(actionMock).toHaveBeenCalled();Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4
line 75why, one step back75});