Skip to content

API reference / @node-ts/bus-core / workflowContext

Function: workflowContext() ​

ts
function workflowContext<TWorkflowState, TMessageAttributes>(context?): WorkflowContext<TWorkflowState, TMessageAttributes>;

Defined in: packages/bus-core/src/workflow/workflow-context.ts:63

Creates a WorkflowContext to call a workflow handler with in a test. send, publish, failMessage and returnMessage do nothing, the attributes are empty, and complete and discard return what the bus expects, unless they're overridden.

Type Parameters ​

Type ParameterDefault type
TWorkflowState extends WorkflowState-
TMessageAttributes extends MessageAttributes<MessageAttributeMap, MessageAttributeMap>MessageAttributes<MessageAttributeMap, MessageAttributeMap>

Parameters ​

ParameterTypeDescription
contextPartial<WorkflowContext<TWorkflowState, TMessageAttributes>>the members to override, such as a send that records what's sent, or the message attributes when the handler reads typed attributes

Returns ​

WorkflowContext<TWorkflowState, TMessageAttributes>

a workflow context

Example ​

ts
const sent: Command[] = []
const ctx = workflowContext<OrderState>({ send: async command => { sent.push(command) } })
const result = await orderWorkflow.startedByHandler(OrderPlaced)(OrderPlaced({ orderId: '1' }), new OrderState(), ctx)

Released under the MIT License.