Skip to content

testing/src

Interfaces

CreateTestWorkflowOptions

Defined in: packages/testing/src/create-test-workflow.ts:10

Options for createTestWorkflow.

Properties

id?

optional id?: string

Defined in: packages/testing/src/create-test-workflow.ts:12

Custom workflow ID. Defaults to "test-{random}".


PathStep

Defined in: packages/testing/src/test-path.ts:13

A single step in a transition path test.

Type Parameters

TConfig

TConfig extends WorkflowConfig

Properties

command

command: CommandNames<TConfig>

Defined in: packages/testing/src/test-path.ts:19

Command to dispatch.

data?

optional data?: { [K in string | number | symbol]: TConfig["_resolved"]["states"][StateNames<TConfig>][K] }

Defined in: packages/testing/src/test-path.ts:17

Initial data for the starting state — required on the first step.

expect

expect: StateNames<TConfig>

Defined in: packages/testing/src/test-path.ts:23

Expected state after dispatch.

payload

payload: { [K in string | number | symbol]: TConfig["_resolved"]["commands"][CommandNames<TConfig>][K] }

Defined in: packages/testing/src/test-path.ts:21

Command payload.

start?

optional start?: StateNames<TConfig>

Defined in: packages/testing/src/test-path.ts:15

Starting state — required on the first step, ignored on subsequent steps.


TestMigrationOptions

Defined in: packages/testing/src/migration-testing.ts:4

Properties

expected

expected: unknown

Defined in: packages/testing/src/migration-testing.ts:7

from

from: number

Defined in: packages/testing/src/migration-testing.ts:5

input

input: unknown

Defined in: packages/testing/src/migration-testing.ts:6

state?

optional state?: string

Defined in: packages/testing/src/migration-testing.ts:8


TestMigrationPathOptions

Defined in: packages/testing/src/migration-testing.ts:11

Properties

expected

expected: unknown

Defined in: packages/testing/src/migration-testing.ts:15

expectVersion

expectVersion: number

Defined in: packages/testing/src/migration-testing.ts:14

from

from: number

Defined in: packages/testing/src/migration-testing.ts:12

input

input: unknown

Defined in: packages/testing/src/migration-testing.ts:13

state?

optional state?: string

Defined in: packages/testing/src/migration-testing.ts:16


TestMigrationRestoreOptions

Defined in: packages/testing/src/migration-testing.ts:19

Properties

expectState?

optional expectState?: string

Defined in: packages/testing/src/migration-testing.ts:22

from

from: number

Defined in: packages/testing/src/migration-testing.ts:20

input

input: unknown

Defined in: packages/testing/src/migration-testing.ts:21

state?

optional state?: string

Defined in: packages/testing/src/migration-testing.ts:23

Functions

createTestDeps()

createTestDeps<T>(partial): T

Defined in: packages/testing/src/create-test-deps.ts:9

Creates a test dependencies object from a partial. Returns the partial cast to the full type — does not proxy or throw on un-stubbed access. Provide only the dependencies your test needs.

Type Parameters

T

T

Parameters

partial

Partial<T>

Partial dependencies object with only the methods/properties your test requires

Returns

T

The partial cast to the full dependency type


createTestWorkflow()

createTestWorkflow<TConfig, S>(definition, state, data, options?): Workflow<TConfig>

Defined in: packages/testing/src/create-test-workflow.ts:25

Creates a workflow in any state without dispatching through the handler chain. Validates data against the state's Zod schema.

Type Parameters

TConfig

TConfig extends WorkflowConfig

S

S extends string

Parameters

definition

WorkflowDefinition<TConfig>

The workflow definition to create from

state

S

The state to place the workflow in

data

{ [K in string | number | symbol]: TConfig["_resolved"]["states"][S][K] }

State data (validated against the state's Zod schema)

options?

CreateTestWorkflowOptions

Optional configuration (e.g., custom ID)

Returns

Workflow<TConfig>

A workflow instance in the specified state


expectError()

expectError<TConfig>(result, category, code?): asserts result is { error: PipelineError<TConfig>; ok: false }

Defined in: packages/testing/src/assertions.ts:31

Asserts that a dispatch result is an error with the given category. Optionally checks the error code (for domain/router errors). Throws on failure — works with any test runner.

Type Parameters

TConfig

TConfig extends WorkflowConfig

Parameters

result

DispatchResult<TConfig>

The dispatch result to assert on

category

"validation" | "domain" | "router" | "unexpected" | "dependency"

Expected error category

code?

string

If provided, also asserts the error code matches (for "domain" and "router" categories)

Returns

asserts result is { error: PipelineError<TConfig>; ok: false }


expectOk()

expectOk<TConfig>(result, expectedState?): asserts result is { events: { data: unknown; type: EventNames<TConfig> }[]; ok: true; workflow: Workflow<TConfig> }

Defined in: packages/testing/src/assertions.ts:10

Asserts that a dispatch result is ok. Optionally checks the resulting state. Throws on failure — works with any test runner.

Type Parameters

TConfig

TConfig extends WorkflowConfig

Parameters

result

DispatchResult<TConfig>

The dispatch result to assert on

expectedState?

string

If provided, also asserts the workflow is in this state

Returns

asserts result is { events: { data: unknown; type: EventNames<TConfig> }[]; ok: true; workflow: Workflow<TConfig> }


testMigration()

testMigration<TConfig>(pipeline, options): void

Defined in: packages/testing/src/migration-testing.ts:57

Tests a single migration step. Calls the migration function for (from + 1) directly and asserts output data matches expected.

Type Parameters

TConfig

TConfig extends WorkflowConfig

Parameters

pipeline

MigrationPipeline<TConfig>

The migration pipeline containing the migration to test

options

TestMigrationOptions

Test configuration: source version, input data, expected output data

Returns

void


testMigrationPath()

testMigrationPath<TConfig>(pipeline, options): void

Defined in: packages/testing/src/migration-testing.ts:83

Tests the full migration chain and asserts final version and data.

Type Parameters

TConfig

TConfig extends WorkflowConfig

Parameters

pipeline

MigrationPipeline<TConfig>

The migration pipeline to run

options

TestMigrationPathOptions

Test configuration: source version, input data, expected final version and data

Returns

void


testMigrationRestore()

testMigrationRestore<TConfig>(pipeline, options): void

Defined in: packages/testing/src/migration-testing.ts:113

Tests migrate + restore round-trip. Derives the definition from the pipeline.

Type Parameters

TConfig

TConfig extends WorkflowConfig

Parameters

pipeline

MigrationPipeline<TConfig>

The migration pipeline to run

options

TestMigrationRestoreOptions

Test configuration: source version, input data, optional expected final state

Returns

void


testPath()

testPath<TConfig, TDeps>(router, definition, steps): Promise<void>

Defined in: packages/testing/src/test-path.ts:35

Tests a sequence of commands and verifies the expected state after each dispatch. Creates the initial workflow from the first step's start/data, then chains dispatch results. Throws on failure — works with any test runner.

Type Parameters

TConfig

TConfig extends WorkflowConfig

TDeps

TDeps

Parameters

router

WorkflowRouter<TConfig, TDeps>

The workflow router to dispatch commands through

definition

WorkflowDefinition<TConfig>

The workflow definition (used to create the initial workflow)

steps

PathStep<TConfig>[]

Array of PathStep objects defining the command sequence

Returns

Promise<void>