import { ... } from "@langchain/core/testing";Creates a new FakeBuiltModel for testing.
Returns a chainable builder — queue responses, then pass the model
anywhere a chat model is expected. Responses are consumed in FIFO
order, one per invoke() call.
| Method | Description |
|---|---|
fakeModel() |
Creates a new fake chat model. Returns a chainable builder. |
.respond(message) |
Queue an AIMessage (or any BaseMessage) to return on the next invocation. |
.respond(error) |
Queue an Error to throw on the next invocation. |
.respond(factory) |
Queue a function (messages) => BaseMessage \| Error for dynamic responses. |
.respondWithTools(toolCalls) |
Shorthand for .respond() with tool calls. Each entry needs name and args; id is optional. |
.alwaysThrow(error) |
Make every invocation throw this error, regardless of the queue. |
.structuredResponse(value) |
Set the value returned by .withStructuredOutput(). |
.bindTools(tools) |
Bind tools to the model. Returns a RunnableBinding that shares the response queue and call recording. |
.withStructuredOutput(schema) |
Returns a runnable that produces the .structuredResponse() value. |
.calls |
Array of { messages, options } for every invocation (read-only). |
.callCount |
Number of times the model has been invoked. |
A fake chat model for testing, created via fakeModel.
Queue responses with .respond() and .respondWithTools(), then
pass the instance directly wherever a chat model is expected.
Responses are consumed in first-in-first-out order — one per invoke() call.
When all queued responses are consumed, further invocations throw.
All matcher functions bundled for convenient use with expect.extend().