Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
setup arg tests
Signed-off-by: shmck <[email protected]>
  • Loading branch information
ShMcK committed Jun 20, 2020
commit 8af064c9a4c719a2c0a75eceef494282c00e3caa
42 changes: 42 additions & 0 deletions tests/args.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { getArg } from "../src/utils/args";

describe("args", () => {
it("should capture an arg name from text", () => {
const args = ["--name", "value"];
const result = getArg(args, { name: "name" });
expect(result).toBe("value");
});
it("should capture an arg alias from text", () => {
const args = ["-n", "value"];
const result = getArg(args, { name: "name", alias: "n" });
expect(result).toBe("value");
});
it("should capture an arg name from text when starting values", () => {
const args = ["dir", "--name", "value"];
const result = getArg(args, { name: "name" });
expect(result).toBe("value");
});
it("should capture an arg alias from text", () => {
const args = ["dir", "-n", "value"];
const result = getArg(args, { name: "name", alias: "n" });
expect(result).toBe("value");
});
it("should default value to true if no next value", () => {
const args = ["--someBool"];
const result = getArg(args, {
name: "someBool",
alias: "sb",
type: "bool",
});
expect(result).toBe(true);
});
it("should default value to true if next value is param", () => {
const args = ["--someBool", "--someOtherBool"];
const result = getArg(args, {
name: "someBool",
alias: "sb",
type: "bool",
});
expect(result).toBe(true);
});
});