fork

open override fun fork(ref: String, name: String, verifyError: Boolean, block: ForkedVerifiedStageDsl<S>.() -> Unit)

Creates a branching test scenario from a previously referenced ExpectStage.

This method allows testing alternative scenarios starting from any previously marked verification point (using ref() in ExpectDsl). It enables complex test flows where multiple branches diverge from the same verified state.

Example usage:

// In your test setup
on {
whenCommand(CreateOrderCommand(...)) {
expectEventType(OrderCreated::class)
ref("order-created") // Mark this verification point
expectState { status.assert().isEqualTo(OrderStatus.CREATED) }
}
}

// Later, create branches from the marked point
fork("order-created", "Pay Order") {
whenCommand(PayOrderCommand(...)) {
expectEventType(OrderPaid::class)
expectState { status.assert().isEqualTo(OrderStatus.PAID) }
}
}
fork("order-created", "Cancel Order") {
whenCommand(CancelOrderCommand(...)) {
expectEventType(OrderCancelled::class)
expectState { status.assert().isEqualTo(OrderStatus.CANCELLED) }
}
}

Parameters

ref

the reference name of a previously marked ExpectStage

name

optional descriptive name for the forked scenario

verifyError

whether to verify that an error occurred at the referenced stage

block

the test scenario to execute in the forked context