---
url: https://node-ts.github.io/bus/api/bus-core/functions/workflowContext.md
---
[API reference](../../index.md) / [@node-ts/bus-core](../index.md) / workflowContext

# Function: workflowContext()

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

Defined in: [packages/bus-core/src/workflow/workflow-context.ts:63](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-core/src/workflow/workflow-context.ts#L63)

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 Parameter | Default type |
| ------ | ------ |
| `TWorkflowState` *extends* [`WorkflowState`](../classes/WorkflowState.md) | - |
| `TMessageAttributes` *extends* [`MessageAttributes`](../../bus-messages/interfaces/MessageAttributes.md)<[`MessageAttributeMap`](../../bus-messages/interfaces/MessageAttributeMap.md), [`MessageAttributeMap`](../../bus-messages/interfaces/MessageAttributeMap.md)> | [`MessageAttributes`](../../bus-messages/interfaces/MessageAttributes.md)<[`MessageAttributeMap`](../../bus-messages/interfaces/MessageAttributeMap.md), [`MessageAttributeMap`](../../bus-messages/interfaces/MessageAttributeMap.md)> |

## Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `context` | `Partial`<[`WorkflowContext`](../interfaces/WorkflowContext.md)<`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`](../interfaces/WorkflowContext.md)<`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)
```
