Chapter 23 alternative test

I tried to do the test func test_whenAccountAvailable_updatesAccountStatus() by myself instead of using expectations.

func test_whenAccountAvailable_updatesAccountStatusV2() {
    let accountSubject = PublishSubject<TwitterAccount.AccountStatus>()
    let viewModel = createViewModel(accountSubject.asDriver(onErrorJustReturn: .unavailable))
    
    let scheduler = TestScheduler(initialClock: 0)
    let observer = scheduler.createObserver(Bool.self)
    


    scheduler.scheduleAt(0) {
        _ = viewModel.loggedIn.asObservable()
            .do(onNext: {status in
                print(status)
            }).subscribe(observer)
        accountSubject.onNext(.authorized(TestData.account))
        accountSubject.onNext(.unavailable)
        accountSubject.onCompleted()
    }
    scheduler.start()

    let expectedEvents = [next(0, true), next(0, false), completed(0)]
    XCTAssertEqual(observer.events, expectedEvents)
}

But seems i get no events in the observable.

Any hints ?

This topic was automatically closed after 166 days. New replies are no longer allowed.