Daily iOS
Testing

Testing an async stream

A live streaming app's chat ViewModel subscribes to incoming messages as an AsyncSequence and appends them to a list. How would you control that message stream in a test?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

Have the ViewModel take the message source as a protocol, pass it a stream made with AsyncStream.makeStream() in tests, and keep the continuation in the test so it calls yield and finish at the moments it chooses and checks how the ViewModel's list changes.

Share a question