-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(command): command action not triggered for standalone options wit…
…hout action handler (#654)
- Loading branch information
Showing
2 changed files
with
71 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { | ||
assertEquals, | ||
assertRejects, | ||
assertSpyCalls, | ||
spy, | ||
} from "../../../dev_deps.ts"; | ||
import { Command } from "../../command.ts"; | ||
|
||
Deno.test("[command] should execute standalone option action", async () => { | ||
const actionSpy = spy(); | ||
const optionActionSpy = spy(); | ||
|
||
const cmd = new Command() | ||
.throwErrors() | ||
.option("--standalone", "description ...", { | ||
action: optionActionSpy, | ||
standalone: true, | ||
}) | ||
.action(actionSpy); | ||
|
||
const { options } = await cmd.parse(["--standalone"]); | ||
|
||
assertSpyCalls(optionActionSpy, 1); | ||
assertSpyCalls(actionSpy, 0); | ||
assertEquals(options, { standalone: true }); | ||
}); | ||
|
||
Deno.test("[command] should execute main action with standalone option", async () => { | ||
const actionSpy = spy(); | ||
|
||
const cmd = new Command() | ||
.throwErrors() | ||
.option("--standalone", "description ...", { | ||
standalone: true, | ||
}) | ||
.action(actionSpy); | ||
|
||
const { options } = await cmd.parse(["--standalone"]); | ||
|
||
assertSpyCalls(actionSpy, 1); | ||
assertEquals(options, { standalone: true }); | ||
}); | ||
|
||
Deno.test("[command] should throw an error if standalone option is combined with other options", async () => { | ||
const actionSpy = spy(); | ||
|
||
const cmd = new Command() | ||
.throwErrors() | ||
.option("--standalone", "description ...", { | ||
standalone: true, | ||
}) | ||
.option("--foo", "description ...") | ||
.action(actionSpy); | ||
|
||
await assertRejects( | ||
() => | ||
cmd.parse( | ||
["--standalone", "--foo"], | ||
), | ||
Error, | ||
'Option "--standalone" cannot be combined with other options.', | ||
); | ||
}); |