Class Contributions
Index
Constructors
constructor
-
Returns Contributions
Accessors
contributor
-
The contributor it lends.
Returns Contributor
Methods
keys
-
The keys contributed under, in the order first contributed.
Returns readonly string[]
read
-
Reads the last value contributed under
keyas the typetypechecks, as the data bag'sreaddoes: 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>>
-
read<S extends StandardSchemaV1<unknown, unknown>>(
key: string,
type: Optional<S>,
): Read<Option<InferInput<S>>>Reads the last value contributed under
keyas the typetypechecks, as the data bag'sreaddoes: 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>
Returns Read<Option<InferInput<S>>>
Lends a contributor outside any journey, so that a test calls a step's
runor 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.