mockAgent()
mockAgent() creates a runtime-neutral Agent mock with writable signals for testing @threadplane/chat components. Use it when you're testing chat UI behavior and don't need LangGraph-specific fields.
Import:
#Signature
#Options
| Option | Type | Default | Description |
|---|---|---|---|
messages | Message[] | [] | Initial runtime-neutral messages |
status | AgentStatus | 'idle' | Initial agent status |
isLoading | boolean | false | Whether the agent is currently running |
error | unknown | null | Initial error value |
toolCalls | ToolCall[] | [] | Initial tool-call list |
state | Record<string, unknown> | {} | Initial agent state |
withInterrupt | boolean | false | Include a writable interrupt signal |
withSubagents | boolean | false | Include a writable subagents signal |
history | AgentCheckpoint[] | undefined | Include history and return an AgentWithHistory-compatible mock |
events$ | Observable<AgentEvent> | EMPTY | Event stream the mock exposes via events$ (defaults to RxJS EMPTY) |
#Basic Test Usage
#Controlling State
The returned mock exposes writable signals, so tests can update state directly:
#Spying on Actions
The mock records calls to core actions:
#Lifecycle and History
mockAgent() exposes a readonly lifecycle.streamStartedAt signal plus an _internal.streamStartedAt writable escape hatch. Use the escape hatch to drive stream-start timing in a test without running a full submit/stream cycle:
The withInterrupt, withSubagents, and history options unlock optional signals — interrupt, subagents, and history are undefined unless you opt in, so tests must null-check (or use ?.) before driving them:
#LangGraph-Specific Tests
Use mockLangGraphAgent() from @threadplane/langgraph only when the test needs LangGraph-specific signals such as raw LangGraph messages, checkpoint state, branches, queued runs, or transport metadata.