simulateReadableStream is a Vercel AI SDK testing helper for producing controlled readable streams from predefined response chunks. It lets tests exercise streaming behavior without making live provider API calls. section 8.4.3
Use it inside a MockLanguageModelV1 doStream implementation passed to streamText. Define text-delta chunks in sequence, then add a finish chunk with its reason and token usage. section 8.4.3
Simulate a streamed response
const result = streamText({ model: new MockLanguageModelV1({ doStream: async () => ({ stream: simulateReadableStream({ chunks: [ { type: 'text-delta', textDelta: 'This is ' }, { type: 'text-delta', textDelta: 'a test ' }, { type: 'text-delta', textDelta: 'of streaming.' }, { type: 'finish', finishReason: 'stop', logprobs: undefined, usage: { completionTokens: 15, promptTokens: 5 } } ] }), rawCall: { rawPrompt: null, rawSettings: {} } }) }), prompt: 'Start streaming!' });
