options.flags.test.js
This file
Path
tests/options.flags.test.js
83 lines · 2.7 KiB · JavaScript
Last changed by
Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384const commander = require('../');
// Test the various ways flags can be specified in the first parameter to `.option`
test('when only short flag defined and not specified then value is undefined', () => { const program = new commander.Command(); program .option('-p', 'add pepper'); program.parse(['node', 'test']); expect(program.opts().p).toBeUndefined();});
test('when only short flag defined and specified then value is true', () => { const program = new commander.Command(); program .option('-p', 'add pepper'); program.parse(['node', 'test', '-p']); expect(program.opts().p).toBe(true);});
test('when only long flag defined and not specified then value is undefined', () => { const program = new commander.Command(); program .option('--pepper', 'add pepper'); program.parse(['node', 'test']); expect(program.opts().pepper).toBeUndefined();});
test('when only long flag defined and specified then value is true', () => { const program = new commander.Command(); program .option('--pepper', 'add pepper'); program.parse(['node', 'test', '--pepper']); expect(program.opts().pepper).toBe(true);});
test('when "short,long" flags defined and short specified then value is true', () => { const program = new commander.Command(); program .option('-p,--pepper', 'add pepper'); program.parse(['node', 'test', '-p']); expect(program.opts().pepper).toBe(true);});
test('when "short,long" flags defined and long specified then value is true', () => { const program = new commander.Command(); program .option('-p,--pepper', 'add pepper'); program.parse(['node', 'test', '--pepper']); expect(program.opts().pepper).toBe(true);});
test('when "short|long" flags defined and short specified then value is true', () => { const program = new commander.Command(); program .option('-p|--pepper', 'add pepper'); program.parse(['node', 'test', '-p']); expect(program.opts().pepper).toBe(true);});
test('when "short|long" flags defined and long specified then value is true', () => { const program = new commander.Command(); program .option('-p|--pepper', 'add pepper'); program.parse(['node', 'test', '--pepper']); expect(program.opts().pepper).toBe(true);});
test('when "short long" flags defined and short specified then value is true', () => { const program = new commander.Command(); program .option('-p --pepper', 'add pepper'); program.parse(['node', 'test', '-p']); expect(program.opts().pepper).toBe(true);});
test('when "short long" flags defined and long specified then value is true', () => { const program = new commander.Command(); program .option('-p --pepper', 'add pepper'); program.parse(['node', 'test', '--pepper']); expect(program.opts().pepper).toBe(true);});