0

我将如何测试看起来像这样的方法?

// in unit test suite

var afterSubscribeClosureEntered = false
viewModel.afterSubscribe = { res in
     afterSubscribeClosureEntered = true
}

viewModel.someMethod()
expect(afterSubscribeClosureEntered).to(beTrue()) // if I used toEventually, it will fail in unit test (time out, unresponsive main loop)

// view model

var afterSubscribe: ((Bool) -> Void)?

func someMethod() {

   observableOne() // method that returns Observable<T>
     .flatMap(observableTwo()) // returns Observable<T>
     .subscribe(onNext: { val in
         // some operation
         self.afterSubscribe?(val)
     })
     .disposed(by: disposeBag)
}

我尝试使用 toEventually 但在 Fastlane 中中断(超时,主循环无响应)。测试套件虽然在 XCode 测试中成功。我不想在中注入completionHandler someMethod。有没有办法在不使用toEventually和waitUntil的情况下测试它?非常感谢!

4

0 回答 0