MockAgentTransport
MockAgentTransport is a deterministic AgentTransport implementation for tests. It records stream calls, lets tests emit LangGraph stream events manually, and avoids a running LangGraph server.
Complete test example
The pattern below covers the full lifecycle: provide a transport instance, create the component, emit stream events, and assert signal state.
MockAgentTransport API
| Method | Description |
|---|---|
constructor(script?) | Optionally seeds scripted event batches for manual stepping. |
nextBatch() | Returns the next scripted event batch. |
emit(events) | Pushes one or more StreamEvent objects into the active stream. |
emitError(err) | Causes the active stream to reject with err. |
close() | Closes the active stream after queued events drain. |
isStreaming() | Returns whether a stream is currently active. |
The transport also records calls in streams, createdQueuedRuns, cancelledRuns, joinedRuns, and historyCalls, which is useful for asserting payloads and options.
MockAgentTransport emits only when your test calls emit(), emitError(),
or close(). This makes stream state and payload assertions deterministic.