argument.required.test.js
This file
Path
tests/argument.required.test.js
34 lines · 1.1 KiB · JavaScript
Last changed by
Feature/argument arg explicit (#1567)John Geebefore adoption6f51e4a
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435const commander = require('../');
// Low-level tests of setting Argument.required.// Higher level tests of optional/required arguments elsewhere.
test('when name with surrounding <> then argument required', () => { const argument = new commander.Argument('<name>'); expect(argument.required).toBe(true);});
test('when name with surrounding [] then argument optional', () => { const argument = new commander.Argument('[name]'); expect(argument.required).toBe(false);});
test('when name without surrounding brackets then argument required', () => { // default behaviour, allowed from Commander 8 const argument = new commander.Argument('name'); expect(argument.required).toBe(true);});
test('when call .argRequired() then argument required', () => { const argument = new commander.Argument('name'); argument.required = false; argument.argRequired(); expect(argument.required).toBe(true);});
test('when call .argOptional() then argument optional', () => { const argument = new commander.Argument('name'); argument.required = true; argument.argOptional(); expect(argument.required).toBe(false);});