Skip to content

Commit

Permalink
test(command): fix depends test
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed Jul 14, 2020
1 parent 88263b5 commit 9ec513c
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions packages/command/test/option/depends_test.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
import { assertThrows } from '../../../flags/test/lib/assert.ts';
import { Command } from '../../lib/command.ts';
import { assertEquals } from '../lib/assert.ts';
import { assertEquals, assertThrowsAsync } from '../lib/assert.ts';

const cmd: Command = new Command()
.throwErrors()
.option( '--flag1', 'flag 1' )
.option( '--flag2 <val:string>', 'flag 2', { depends: [ 'flag1' ], default: 'example' } );
function command(): Command {
return new Command()
.throwErrors()
.option( '-f, --flag1', 'flag 1' )
.option( '-F, --flag2 <val:string>', 'flag 2', { depends: [ 'flag1' ], default: 'example' } );
}

Deno.test( 'command depends option with default value: should accept no arguments', async () => {

const { options, args } = await cmd.parse( [] );
const { options, args } = await command().parse( [] );

assertEquals( options, { flag2: 'example' } );
assertEquals( args, [] );
} );

Deno.test( 'command depends option with default value: should accept -h', async () => {

const { options, args } = await cmd.parse( [ '-h' ] );

assertEquals( options, { flag2: 'example' } );
assertEquals( args, [] );
} );
// disabled because the -h flag call's Deno.exit() and stops the test's.
// Deno.test( 'command depends option with default value: should accept -h', async () => {
//
// const { options, args } = await cmd().parse( [ '-h' ] );
//
// assertEquals( options, { flag2: 'example' } );
// assertEquals( args, [] );
// } );

Deno.test( 'command depends option with default value: should accept --flag1', async () => {

const { options, args } = await cmd.parse( [ '--flag1' ] );
const { options, args } = await command().parse( [ '--flag1' ] );

assertEquals( options, { flag1: true, flag2: 'example' } );
assertEquals( args, [] );
} );

Deno.test( 'command depends option with default value: should accept --flag1 --flag2 test', async () => {

const { options, args } = await cmd.parse( [ '--flag1', '--flag2', 'test' ] );
const { options, args } = await command().parse( [ '--flag1', '--flag2', 'test' ] );

assertEquals( options, { flag1: true, flag2: 'test' } );
assertEquals( args, [] );
} );

Deno.test( 'command depends option with default value: should not accept --flag2 test', async () => {

assertThrows(
() => cmd.parse( [ '--flag2', 'test' ] ),
Error,
'Option --flag2 depends on option: --flag1'
);
await assertThrowsAsync( async () => {
await command().parse( [ '--flag2', 'test' ] );
}, Error, 'Option --flag2 depends on option: --flag1' );
} );

0 comments on commit 9ec513c

Please sign in to comment.