Chapter 23: ListTimeLineViewModelTests using RxBlocking

Hey there,

I tried to convert the test_whenAccountAvailable_updatesAccountStatus() test to a version using RxBlocking but I’m stuck.

My current code looks like this:

func test_whenAccountAvailable_updatesAccountStatus() {
let accountSubject = PublishSubject<TwitterAccount.AccountStatus>()
let viewModel = createViewModel(accountSubject.asDriver(onErrorJustReturn: .unavailable))

let loggedInObservable = viewModel.loggedIn.asObservable().subscribeOn(scheduler)


XCTAssertEqual(try! loggedInObservable.toBlocking().toArray(), [true, false])

I get the error that [] doesn’t equal [true, false]. It seems to me that the assert starts after the subject is already completed. If I use ‘DispatchQueue.main.asyncAfter’ with a delay of 0.01 the code works, but this can’t be the right solution. Could someone explain me what I’m doing wrong?