Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests for implies #1730

Merged
merged 1 commit into from May 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions tests/options.implies.test.js
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);
});