Fixture
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.
Classes
Section titled “Classes”ExpectationFailed
Section titled “ExpectationFailed”Defined in: src/Fixture.ts:31
Raised as a defect, so a command’s error channel only holds what the command can do.
Extends
Section titled “Extends”object&YieldableError<this>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ExpectationFailed(…
args):ExpectationFailed
Defined in: node_modules/.pnpm/effect@4.0.6/node_modules/effect/dist/Schema.d.ts:10979
Parameters
Section titled “Parameters”…[props: object, options?: MakeOptions]
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Schema.TaggedError<ExpectationFailed>()("ExpectationFailed", { message: Schema.String, expected: Schema.Unknown, actual: Schema.Unknown }).constructor
Properties
Section titled “Properties”actual
Section titled “actual”
readonlyactual:unknown=Schema.Unknown
Defined in: src/Fixture.ts:34
Inherited from
Section titled “Inherited from”Schema.TaggedError<ExpectationFailed>()("ExpectationFailed", { message: Schema.String, expected: Schema.Unknown, actual: Schema.Unknown }).actual
expected
Section titled “expected”
readonlyexpected:unknown=Schema.Unknown
Defined in: src/Fixture.ts:33
Inherited from
Section titled “Inherited from”Schema.TaggedError<ExpectationFailed>()("ExpectationFailed", { message: Schema.String, expected: Schema.Unknown, actual: Schema.Unknown }).expected
message
Section titled “message”message:
string=Schema.String
Defined in: src/Fixture.ts:32
Inherited from
Section titled “Inherited from”Schema.TaggedError<ExpectationFailed>()("ExpectationFailed", { message: Schema.String, expected: Schema.Unknown, actual: Schema.Unknown }).message
Interfaces
Section titled “Interfaces”Fixture
Section titled “Fixture”Defined in: src/Fixture.ts:97
Type Parameters
Section titled “Type Parameters”A extends Any
Properties
Section titled “Properties”Defined in: src/Fixture.ts:103
The state after the given events, without running a command.
Methods
Section titled “Methods”checkInvariants()
Section titled “checkInvariants()”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.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”Effect<void, never, Context<A>>
given()
Section titled “given()”given(
events):Fixture<A>
Defined in: src/Fixture.ts:99
Replaces the history the next command runs against.
Parameters
Section titled “Parameters”events
Section titled “events”readonly GivenEvent<A>[]
Returns
Section titled “Returns”Fixture<A>
givenEvents()
Section titled “givenEvents()”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.
Parameters
Section titled “Parameters”events?
Section titled “events?”readonly GivenEvent<A>[]
aggregateId?
Section titled “aggregateId?”string
Returns
Section titled “Returns”Fixture<A>
inspectState()
Section titled “inspectState()”Defined in: src/Fixture.ts:105
Passes the state after the given events to a callback, which throws to fail the test.
Parameters
Section titled “Parameters”(state) => void
Returns
Section titled “Returns”Scenario<A, ReadError, Context<A>>
when()
Section titled “when()”when<
K>(command,payload):Scenario<A,CommandFailure|CommandError<A,K>,Context<A>>
Defined in: src/Fixture.ts:108
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”command
Section titled “command”K
payload
Section titled “payload”Payload<A, K>
Returns
Section titled “Returns”Scenario<A, CommandFailure | CommandError<A, K>, Context<A>>
whenFails()
Section titled “whenFails()”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.
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”command
Section titled “command”K
payload
Section titled “payload”Payload<A, K>
Returns
Section titled “Returns”Effect<CommandFailure | CommandError<A, K>, never, Context<A>>
InvariantOptions
Section titled “InvariantOptions”Defined in: src/Fixture.ts:56
Type Parameters
Section titled “Type Parameters”A extends Any
Properties
Section titled “Properties”check?
Section titled “check?”
readonlyoptionalcheck?:CheckOptions
Defined in: src/Fixture.ts:71
Passed on to Arbitrary.checkEffect, for the number of runs or a seed.
commands?
Section titled “commands?”
readonlyoptionalcommands?: { 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.
invariant
Section titled “invariant”
readonlyinvariant: (state) =>boolean
Defined in: src/Fixture.ts:58
Must hold for the given state and after every command that succeeds.
Parameters
Section titled “Parameters”State<A>
Returns
Section titled “Returns”boolean
maxCommands?
Section titled “maxCommands?”
readonlyoptionalmaxCommands?:number
Defined in: src/Fixture.ts:69
The longest sequence of commands to try. Defaults to 20.
Outcome
Section titled “Outcome”Defined in: src/Fixture.ts:37
Type Parameters
Section titled “Type Parameters”A extends Any
Properties
Section titled “Properties”events
Section titled “events”
readonlyevents: readonlyEvent<A>[]
Defined in: src/Fixture.ts:38
fixture
Section titled “fixture”
readonlyfixture:Fixture<A>
Defined in: src/Fixture.ts:42
Continues from here, with this outcome’s events as the new history.
readonlystate:State<A>
Defined in: src/Fixture.ts:39
version
Section titled “version”
readonlyversion:number
Defined in: src/Fixture.ts:40
Scenario
Section titled “Scenario”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.
Extends
Section titled “Extends”Effect<Outcome<A>,E,R>
Type Parameters
Section titled “Type Parameters”A extends Any
E
R
Methods
Section titled “Methods”expectEvent()
Section titled “expectEvent()”expectEvent(
event):Scenario<A,E,R>
Defined in: src/Fixture.ts:90
Expects the last command to have emitted exactly this event.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Scenario<A, E, R>
expectEvents()
Section titled “expectEvents()”expectEvents(
events):Scenario<A,E,R>
Defined in: src/Fixture.ts:92
Expects the last command to have emitted exactly these events, in order.
Parameters
Section titled “Parameters”events
Section titled “events”readonly ExpectedEvent<A>[]
Returns
Section titled “Returns”Scenario<A, E, R>
inspectState()
Section titled “inspectState()”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.
Parameters
Section titled “Parameters”(state) => void
Returns
Section titled “Returns”Scenario<A, E, R>
when()
Section titled “when()”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.
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”command
Section titled “command”K
payload
Section titled “payload”Payload<A, K>
Returns
Section titled “Returns”Scenario<A, CommandFailure | E | CommandError<A, K>, R | Context<A>>
whenFails()
Section titled “whenFails()”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.
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”command
Section titled “command”K
payload
Section titled “payload”Payload<A, K>
Returns
Section titled “Returns”Effect<CommandFailure | CommandError<A, K>, E, R | Context<A>>
Type Aliases
Section titled “Type Aliases”ExpectedEvent
Section titled “ExpectedEvent”Defined in: src/Fixture.ts:46
An event to compare with, or only its tag when the rest doesn’t matter.
Type Parameters
Section titled “Type Parameters”A extends Any
GivenEvent
Section titled “GivenEvent”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.
Type Parameters
Section titled “Type Parameters”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.
Type Parameters
Section titled “Type Parameters”A extends Any
Functions
Section titled “Functions”make()
Section titled “make()”make<
A>(aggregate,options?):Fixture<A>
Defined in: src/Fixture.ts:188
Type Parameters
Section titled “Type Parameters”A extends Any
Parameters
Section titled “Parameters”aggregate
Section titled “aggregate”A
options?
Section titled “options?”aggregateId?
Section titled “aggregateId?”string
events?
Section titled “events?”readonly GivenEvent<A>[]
Returns
Section titled “Returns”Fixture<A>