Skip to content

Commit

Permalink
Add more tests for implies (#1730)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn authored May 23, 2022
1 parent 1bab84c commit 3103c6b
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/options.implies.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,34 @@ test('when requiredOption with implied value then not throw', () => {
program.parse(['--default-target'], { from: 'user' });
}).not.toThrow();
});

test('when implies on program and use subcommand then program updated', () => {
const program = new Command();
program
.addOption(new Option('--foo').implies({ bar: 'implied' }));
program
.command('sub')
.action(() => {});
program.parse(['--foo', 'sub'], { from: 'user' });
expect(program.opts().bar).toEqual('implied');
});

test('when option with implies used multiple times then implied gets single value', () => {
const program = new Command();
program
.addOption(new Option('--foo').implies({ bar: 'implied' }))
.option('-b, --bar <value...>');
program.parse(['--foo', '--foo'], { from: 'user' });
expect(program.opts().bar).toEqual('implied');
});

test('when implied option has custom processing then custom processing not called', () => {
let called = false;
const program = new Command();
program
.addOption(new Option('--foo').implies({ bar: true }))
.option('-b, --bar', 'description', () => { called = true; });
program.parse(['--foo'], { from: 'user' });
expect(program.opts().bar).toEqual(true);
expect(called).toEqual(false);
});

0 comments on commit 3103c6b

Please sign in to comment.