RxSwift 1.1 Chapter 16 page 311

There is 2 ways writing tests in this page, one is doing it in waitForExpectations way, another is using RxBlocking to write the test. We have to skip 1 when subscribe to color in first test, reason way is that subscribing to color driver will replay initial value upon subscription. My question is, why there is no need to skip 1 while using blocking to do the test? Will guard let result = try colorObservable.toBlocking(timeout: 1.0).first() else { return } ignore replay value upon subscription?

Hey! I’ve invited @scotteg to the discussion as he hopefully will be able to provide a better answer for you than I would be able to :stuck_out_tongue:

In the expectation example, we subscribe and then add the hexString value. So we use skip to ignore the initial element emitted by the driver. In the blocking example, we just add the hexString value onto the observable and then use toBlocking(timeout:).first() to get that value.

1 Like

I’ve figured out what’s going on here, thanks for your response!

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