title: How to test a combineLatest observable with RxTest?
body: <p>So I have this viewModel which has a validation observable that is simply the combination of 5 other signals into a boolean.</p>
  
  <pre><code>import RxSwift
  
  class SchedulingFormViewModel: BaseViewModel {
  
      let places = Variable&lt;[String]&gt;([])
  
      var formIsValid: Observable&lt;Bool&gt;!
  
      override init() {
          super.init()
          places.value = ["LUGAR 1", "LUGAR 2", "LUGAR 3"]
  
          formIsValid = Observable.combineLatest(UserSession.currenctScheduling.dateSignal.asObservable(),
                                                 UserSession.currenctScheduling.carSignal.asObservable(),
                                                 UserSession.currenctScheduling.locationSignal.asObservable(),
                                                 UserSession.currenctScheduling.servicesSignal.asObservable())
          { (date: Date?, car: Car?, location: String?, services: [Service]?) in
              print("DATE: \(date), CAR: \(car), LOCATION: \(location), SERVICES:\(services)")
              guard let servicesArray = services else { return false }
              let valid = date != nil &amp;&amp; car != nil &amp;&amp; location != nil &amp;&amp; servicesArray.count &gt; 0
              return valid
          }
      }
  }
  </code></pre>
  
  <p>And then I have my test class with a method that should just test whether the signal changes or not. I've tried a variety of approaches but none of them really gets the true value at the end. The observable only emits a true signal after the test has run.</p>
  
  <p>My test class is setup like this</p>
  
  <pre><code>import XCTest
  
  import RxSwift
  import RxTest
  
  @testable import Automobi
  
  class SchedulingUnitTests: XCTestCase {
  
      var viewModel: SchedulingFormViewModel!
      var disposeBag: DisposeBag!
      var scheduler: TestScheduler!
  
      override func setUp() {
          super.setUp()
          viewModel = SchedulingFormViewModel()
          UserSession.clearScheduling()
          disposeBag = DisposeBag()
          scheduler = TestScheduler(initialClock: 0) 
      }
  }
  </code></pre>
  
  <p>I've tried the TestScheduler</p>
  
  <pre><code>func testFormValidation() {
      UserSession.currenctScheduling.dateSignal.value = Date()
      UserSession.currenctScheduling.carSignal.value = Car()
      UserSession.currenctScheduling.servicesSignal.value = [Service(), Service()]
  
      let location = scheduler.createHotObservable([
          next(100, "TEST")
      ])
  
      location.subscribe(onNext: { (text) in
          print("LOCATION: \(text)")
          UserSession.currenctScheduling.locationSignal.value = text
      }).addDisposableTo(disposeBag)
  
  
      let results = scheduler.createObserver(Bool.self)
  
      scheduler.scheduleAt(0) { 
          self.viewModel.formIsValid.subscribe(results).addDisposableTo(self.disposeBag)
      }
  
      let expected = [
          next(100, true)
      ]
  
      scheduler.start()
  
      XCTAssertEqual(results.events, expected)
  }
  </code></pre>
  
  <p>Also</p>
  
  <pre><code>func testFormValidation() {
      UserSession.currenctScheduling.dateSignal.value = Date()
      UserSession.currenctScheduling.carSignal.value = Car()
      UserSession.currenctScheduling.servicesSignal.value = [Service(), Service()]
  
      let location = scheduler.createHotObservable([
          next(100, "TEST"),
          next(150, "TEST 2"),
          next(200, "TEST 3")
          ])
  
      location.subscribe(onNext: { (text) in
          print("LOCATION: \(text)")
          UserSession.currenctScheduling.locationSignal.value = text
      }).addDisposableTo(disposeBag)
  
  
      var results = [Bool]()
      viewModel.formIsValid.subscribe(onNext: { (value) in
          results.append(value)
      }).addDisposableTo(disposeBag)
  
      let expected = [true, true, true]
  
      scheduler.start()
  
      XCTAssertEqual(results, expected)
  }
  </code></pre>
  
  <p>I've tried things like binding my formIsValid to a Variable and verifying its value at the end.</p>
  
  <pre><code>func testFormValidation() {
          UserSession.currenctScheduling.dateSignal.value = Date()
          UserSession.currenctScheduling.carSignal.value = Car()
          UserSession.currenctScheduling.locationSignal.value = "TESTE"
          UserSession.currenctScheduling.servicesSignal.value = [Service(), Service()]
  
          sleep(5)
  
          XCTAssertTrue(viewModel.formIsValid.value)
  }
  </code></pre>
  
  <p>But I never get the expected result. I do get a true signal after all the tests fail and the code goes back to executing. Also when running the app the code executes as expecte I just need to catch it in the test. Any ideas?!</p>