Class Contributions

Lends a contributor outside any journey, so that a test calls a step's run or a hook itself, and keeps what is contributed through it. The contributor behaves as in a journey, but nothing is committed: committing a successful attempt's contributions belongs to a journey.

import assert from "node:assert/strict";
import { type Contributor, contributor } from "itinera/journey";
import { type Outcome, Step, step } from "itinera/step";
import { Contributions } from "itinera/testing";
import { integer } from "itinera/value";

@step()
class Charge extends Step {
override run(@contributor() contributor: Contributor): Outcome {
contributor.contribute("charged", 40);
return this.succeed();
}
}

const contributions = new Contributions();

new Charge().run(contributions.contributor);

assert.deepEqual(contributions.keys(), ["charged"]);
assert.equal(contributions.read("charged", integer).option().unwrap(), 40);

Index

  • The keys contributed under, in the order first contributed.

    Returns readonly string[]

  • Reads the last value contributed under key as the type type checks, as the data bag's read does: present, absent or of another type.

    import assert from "node:assert/strict";
    import { type Contributor, contributor } from "itinera/journey";
    import { type Outcome, Step, step } from "itinera/step";
    import { Contributions } from "itinera/testing";
    import { integer } from "itinera/value";

    @step()
    class Charge extends Step {
    override run(@contributor() contributor: Contributor): Outcome {
    contributor.contribute("charged", 40);
    return this.succeed();
    }
    }

    const contributions = new Contributions();

    new Charge().run(contributions.contributor);

    assert.deepEqual(contributions.keys(), ["charged"]);
    assert.equal(contributions.read("charged", integer).option().unwrap(), 40);

    Type Parameters

    • S extends StandardSchemaV1<unknown, unknown>

    Parameters

    • key: string
    • type: S

    Returns Read<InferInput<S>>

  • Reads the last value contributed under key as the type type checks, as the data bag's read does: present, absent or of another type.

    import assert from "node:assert/strict";
    import { type Contributor, contributor } from "itinera/journey";
    import { type Outcome, Step, step } from "itinera/step";
    import { Contributions } from "itinera/testing";
    import { integer } from "itinera/value";

    @step()
    class Charge extends Step {
    override run(@contributor() contributor: Contributor): Outcome {
    contributor.contribute("charged", 40);
    return this.succeed();
    }
    }

    const contributions = new Contributions();

    new Charge().run(contributions.contributor);

    assert.deepEqual(contributions.keys(), ["charged"]);
    assert.equal(contributions.read("charged", integer).option().unwrap(), 40);

    Type Parameters

    • S extends StandardSchemaV1<unknown, unknown>

    Parameters

    Returns Read<Option<InferInput<S>>>