It's my first time using RxTest and I am struggling how to do the following approach:
protocol ViewModelType {
func transform(input: ViewModel.Input) -> ViewModel.Output
}
struct ViewModel: ViewModelType {
private let isLoading = PublishSubject<Bool>()
struct Input {
let trigger: PublishSubject<Void>
}
struct Output {
let someAction: Observable<Void>
let isLoading: Observable<Bool>
}
func transform(input: Input) -> Output {
let someAction = input
.trigger
.do(onNext: { _ in
self.isLoading.onNext(true)
//do some async task
self.isLoading.onNext(false)
})
return Output(someAction: someAction, isLoading: isLoading)
}
}
I have created a Publish Subject inside the viewModel to notify the view when it should show the loader or not.
Everything works fine, excepts I don't know how to test it with the RxTest framework.
I was trying to use the scheduler and cold observables but couldn't manage to make it work.
What I would like to have:
- With the scheduler send the .next(10, ()) to the trigger.
- Somehow record the events of the isLoading and assert equal that goes first true and then false. Like that: [.next(10, true), .next(20, false)].
Maybe, the isLoading the way I did it, it's not testable. But seems it's going out through the Output I think maybe there is some way.
Thank you so much, if something is unclear, please feel free to edit or guide me to a better question. Much appreciated.