DevPrep

All topics › Combine

How do you test Combine pipelines?

Middle PRO

The gist

A Combine pipeline is tested like an "inputs → outputs" function: feed in values (a subject, @Published, an API stub), collect what the subscriber received, and compare. Two things get in the way — asynchrony (values arrive later) and time (debounce, delay, throttle, timeout). Both are solved by injection: dependencies return synchronous publishers (Just, Fail, a subject), and the scheduler is passed in from outside.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store