# test.govlab/argv/core/converters/invocation.converter.test.ts

> 35 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-govlab-argv-core-converters-invocation-converter-test-ts
Source text: https://banes-lab.com/source/testing/test.govlab/argv/core/converters/invocation.converter.test.ts.txt

Listed in [test.govlab/argv/core/converters](https://banes-lab.com/api/source/testing/test.govlab/argv/core/converters.md), before [test.govlab/argv/core/converters/invocation.fixture.ts](https://banes-lab.com/source/testing/test.govlab/argv/core/converters/invocation.fixture.ts.md).

## Contained in

- [test.govlab/argv/core/converters](https://banes-lab.com/anatomy/testing/folder-testing-test-govlab-argv-core-converters.md)

## Source

```typescript
import { FULL_WORDS, SPEC } from "./invocation.fixture.ts";
import { describe, expect, it } from "vitest";
import {
    missingValue,
    repeatedFlag,
    tooFewPositionals,
    tooManyPositionals,
    undeclaredFlag,
} from "@govlab/argv/configuration/strings/invocation.strings.ts";
import { parseArgv } from "@govlab/argv";

describe("parseArgv", () => {
    it("parses declared flags and positionals", () => {
        const outcome = parseArgv(SPEC, FULL_WORDS);
        expect(outcome.kind).toBe("parsed");
        expect(outcome.kind === "parsed" ? outcome.argv.positionals : []).toStrictEqual(["in"]);
    });

    it("answers help before anything else", () => {
        expect(parseArgv(SPEC, ["--bogus", "--help"]).kind).toBe("help");
        expect(parseArgv(SPEC, ["-h"]).kind).toBe("help");
    });

    it.each([
        [["in", "--bogus"], undeclaredFlag("--bogus", SPEC.command)],
        [["in", "--name"], missingValue("--name")],
        [["in", "--name", "a", "--name", "b"], repeatedFlag("--name")],
        [[], tooFewPositionals(0, 1)],
        [["a", "b"], tooManyPositionals(2, 1, ["a", "b"])],
    ])("refuses %j with its reason", (words, reason) => {
        const outcome = parseArgv(SPEC, words);
        expect(outcome.kind === "refused" ? outcome.reason : "").toBe(reason);
    });

    it("passes the words after every positional through as rest when the contract declares one", () => {
        const outcome = parseArgv({ ...SPEC, rest: { describe: "passed on", name: "args" } }, ["in", "--bogus"]);
        expect(outcome.kind === "parsed" ? outcome.argv.rest : []).toStrictEqual(["--bogus"]);
    });
});
```
