|
| 1 | +import { getArg } from "../src/utils/args"; |
| 2 | + |
| 3 | +describe("args", () => { |
| 4 | + it("should capture an arg name from text", () => { |
| 5 | + const args = ["--name", "value"]; |
| 6 | + const result = getArg(args, { name: "name" }); |
| 7 | + expect(result).toBe("value"); |
| 8 | + }); |
| 9 | + it("should capture an arg alias from text", () => { |
| 10 | + const args = ["-n", "value"]; |
| 11 | + const result = getArg(args, { name: "name", alias: "n" }); |
| 12 | + expect(result).toBe("value"); |
| 13 | + }); |
| 14 | + it("should capture an arg name from text when starting values", () => { |
| 15 | + const args = ["dir", "--name", "value"]; |
| 16 | + const result = getArg(args, { name: "name" }); |
| 17 | + expect(result).toBe("value"); |
| 18 | + }); |
| 19 | + it("should capture an arg alias from text", () => { |
| 20 | + const args = ["dir", "-n", "value"]; |
| 21 | + const result = getArg(args, { name: "name", alias: "n" }); |
| 22 | + expect(result).toBe("value"); |
| 23 | + }); |
| 24 | + it("should default value to true if no next value", () => { |
| 25 | + const args = ["--someBool"]; |
| 26 | + const result = getArg(args, { |
| 27 | + name: "someBool", |
| 28 | + alias: "sb", |
| 29 | + type: "bool", |
| 30 | + }); |
| 31 | + expect(result).toBe(true); |
| 32 | + }); |
| 33 | + it("should default value to true if next value is param", () => { |
| 34 | + const args = ["--someBool", "--someOtherBool"]; |
| 35 | + const result = getArg(args, { |
| 36 | + name: "someBool", |
| 37 | + alias: "sb", |
| 38 | + type: "bool", |
| 39 | + }); |
| 40 | + expect(result).toBe(true); |
| 41 | + }); |
| 42 | +}); |
0 commit comments