Skip to content

Tests an aggregate in isolation: given these events, when this command runs, what happens? The moleculer-cqrs CQRSFixture, as a chain that runs when it is yielded:

yield* Fixture.make(Todo)
.givenEvents([created])
.when("deleteTodo", { message: "Done" })
.expectEvent("TodoDeleted")
.inspectState((state) => assert.strictEqual(state.status, "deleted"))

Commands run through the real AggregateService on an in-memory store, so payload validation and event encoding are exercised too.

The history can include events stored in older versions of their schema, made with Aggregate.historical, which then go through the same upcasting as events read from a real store.

Defined in: src/Fixture.ts:31

Raised as a defect, so a command’s error channel only holds what the command can do.

  • object & YieldableError<this>

new ExpectationFailed(…args): ExpectationFailed

Defined in: node_modules/.pnpm/effect@4.0.6/node_modules/effect/dist/Schema.d.ts:10979

…[props: object, options?: MakeOptions]

ExpectationFailed

Schema.TaggedError<ExpectationFailed>()("ExpectationFailed", { message: Schema.String, expected: Schema.Unknown, actual: Schema.Unknown }).constructor

readonly actual: unknown = Schema.Unknown

Defined in: src/Fixture.ts:34

Schema.TaggedError<ExpectationFailed>()("ExpectationFailed", { message: Schema.String, expected: Schema.Unknown, actual: Schema.Unknown }).actual

readonly expected: unknown = Schema.Unknown

Defined in: src/Fixture.ts:33

Schema.TaggedError<ExpectationFailed>()("ExpectationFailed", { message: Schema.String, expected: Schema.Unknown, actual: Schema.Unknown }).expected

message: string = Schema.String

Defined in: src/Fixture.ts:32

Schema.TaggedError<ExpectationFailed>()("ExpectationFailed", { message: Schema.String, expected: Schema.Unknown, actual: Schema.Unknown }).message

Defined in: src/Fixture.ts:97

A extends Any

readonly state: Effect<State<A>, ReadError, Context<A>>

Defined in: src/Fixture.ts:103

The state after the given events, without running a command.

checkInvariants(options): Effect<void, never, Context<A>>

Defined in: src/Fixture.ts:123

Runs random sequences of commands from the given history and checks that the invariant holds after each one that succeeds. Commands that fail are part of the game and are skipped. A violation dies with ExpectationFailed, holding the shortest sequence found that breaks it.

InvariantOptions<A>

Effect<void, never, Context<A>>

given(events): Fixture<A>

Defined in: src/Fixture.ts:99

Replaces the history the next command runs against.

readonly GivenEvent<A>[]

Fixture<A>

givenEvents(events?, aggregateId?): Fixture<A>

Defined in: src/Fixture.ts:101

Like given, starting from an empty history by default and optionally switching aggregate id.

readonly GivenEvent<A>[]

string

Fixture<A>

inspectState(check): Scenario<A, ReadError, Context<A>>

Defined in: src/Fixture.ts:105

Passes the state after the given events to a callback, which throws to fail the test.

(state) => void

Scenario<A, ReadError, Context<A>>

when<K>(command, payload): Scenario<A, CommandFailure | CommandError<A, K>, Context<A>>

Defined in: src/Fixture.ts:108

K extends string

K

Payload<A, K>

Scenario<A, CommandFailure | CommandError<A, K>, Context<A>>

whenFails<K>(command, payload): Effect<CommandFailure | CommandError<A, K>, never, Context<A>>

Defined in: src/Fixture.ts:113

Runs a command that is expected to fail and returns the error. Dies if it succeeds.

K extends string

K

Payload<A, K>

Effect<CommandFailure | CommandError<A, K>, never, Context<A>>


Defined in: src/Fixture.ts:56

A extends Any

readonly optional check?: CheckOptions

Defined in: src/Fixture.ts:71

Passed on to Arbitrary.checkEffect, for the number of runs or a seed.

readonly optional commands?: { readonly [K in string]?: false | Arbitrary<Payload<A, K>> }

Defined in: src/Fixture.ts:63

How to generate each command’s payload. By default it comes from the payload schema. false leaves a command out.

readonly invariant: (state) => boolean

Defined in: src/Fixture.ts:58

Must hold for the given state and after every command that succeeds.

State<A>

boolean

readonly optional maxCommands?: number

Defined in: src/Fixture.ts:69

The longest sequence of commands to try. Defaults to 20.


Defined in: src/Fixture.ts:37

A extends Any

readonly events: readonly Event<A>[]

Defined in: src/Fixture.ts:38

readonly fixture: Fixture<A>

Defined in: src/Fixture.ts:42

Continues from here, with this outcome’s events as the new history.

readonly state: State<A>

Defined in: src/Fixture.ts:39

readonly version: number

Defined in: src/Fixture.ts:40


Defined in: src/Fixture.ts:78

The steps so far. Nothing runs until it is yielded or run as an Effect, which produces the Outcome of the last command.

A extends Any

E

R

expectEvent(event): Scenario<A, E, R>

Defined in: src/Fixture.ts:90

Expects the last command to have emitted exactly this event.

ExpectedEvent<A>

Scenario<A, E, R>

expectEvents(events): Scenario<A, E, R>

Defined in: src/Fixture.ts:92

Expects the last command to have emitted exactly these events, in order.

readonly ExpectedEvent<A>[]

Scenario<A, E, R>

inspectState(check): Scenario<A, E, R>

Defined in: src/Fixture.ts:94

Passes the current state to a callback, which throws to fail the test.

(state) => void

Scenario<A, E, R>

when<K>(command, payload): Scenario<A, CommandFailure | E | CommandError<A, K>, R | Context<A>>

Defined in: src/Fixture.ts:80

Runs another command on top of the previous one.

K extends string

K

Payload<A, K>

Scenario<A, CommandFailure | E | CommandError<A, K>, R | Context<A>>

whenFails<K>(command, payload): Effect<CommandFailure | CommandError<A, K>, E, R | Context<A>>

Defined in: src/Fixture.ts:85

Runs a command that is expected to fail and returns the error. Dies if it succeeds.

K extends string

K

Payload<A, K>

Effect<CommandFailure | CommandError<A, K>, E, R | Context<A>>

ExpectedEvent<A> = Event<A> | Event<A>["_tag"]

Defined in: src/Fixture.ts:46

An event to compare with, or only its tag when the rest doesn’t matter.

A extends Any


GivenEvent<A> = Event<A> | Historical

Defined in: src/Fixture.ts:49

An event in today’s shape, or one stored in an older version of its schema.

A extends Any


Step<A> = { readonly [K in CommandName<A>]: { command: K; payload: Payload<A, K> } }[CommandName<A>]

Defined in: src/Fixture.ts:52

One generated step of Fixture.checkInvariants.

A extends Any

make<A>(aggregate, options?): Fixture<A>

Defined in: src/Fixture.ts:188

A extends Any

A

string

readonly GivenEvent<A>[]

Fixture<A>