title: How To UnitTest Combine Cancellables?
body: <blockquote>
  <p>How to write unit test for this func loadDemos()?</p>
  <p>Here is the code</p>
  </blockquote>
  <pre><code>class BenefitViewModel: ObservableObject {
  
  func loadDemos()  {
              let testMode =  ProcessInfo.processInfo.arguments.contains(&quot;testMode&quot;)
              if testMode {
                  self.demos = DummyData().decodeDemos()
              } else {
                  cancellables.insert(self.getDemos().sink(receiveCompletion: { result in
                      switch result {
                      case .failure(let error):
                          print(error.localizedDescription)
                          break
                      case .finished:
                          break
                      }
                  }, receiveValue: { response in
                      self.demos = response
                      print(“Demos: \(response.count)&quot;)
                  }))
              }
          }
      }
  </code></pre>