Testing a Streaming AI UI: Fake Streams, Vitest Fake Timers, MSW and Playwright
A streaming AI UI is tested deterministically with fake AsyncGenerators that take the model out of the loop, fake timers, MSW responses with ReadableStream bodies and Playwright tests using page.route. In this post we show instanceof DOMException turning a cancellation into an error in the test environment, MSW's sse() handler not fitting a fetch stream, and a ping-less fake stream hitting the 15 s silence timer before the 30 s timeout; 18 tests finish in under 2 seconds.
14 Nov 2026
·
16 min
·
2