ReactiveX / RxSwift

Reactive Programming in Swift
MIT License
24.37k stars 4.17k forks source link

RxBlocking & RxTest does't work well with PublishSubject #1480

Closed huy-le closed 6 years ago

huy-le commented 6 years ago

Short description of the issue:

I'd like to test a PublishSubject to know how many events it published. However, the RxBlocking & RxTest doesn't help. It always returns nil.

Expected outcome:

result.count > 0

What actually happens:

result.count == 0

Self contained code example that reproduces the issue:

    func testPublishSubject() {
        let subject = PublishSubject<String>()
        subject.onNext("Abc")
        subject.onCompleted()
        do {
            let result = try subject.toBlocking().toArray()
            XCTAssert(result.count == 1)
        } catch {
            // Ignore
        }
    }

RxSwift/RxCocoa/RxBlocking/RxTest version/commit

3.6.1

Platform/Environment

How easy is to reproduce? (chances of successful reproduce after running the self contained code)

Xcode version:

  XCode 9.0

:warning: Fields below are optional for general issues or in case those questions aren't related to your issue, but filling them out will increase the chances of getting your issue resolved. :warning:

Installation method:

I have multiple versions of Xcode installed: (so we can know if this is a potential cause of your issue)

Level of RxSwift knowledge: (this is so we can understand your level of knowledge and formulate the response in an appropriate manner)

abdulowork commented 6 years ago

I think that is expected because PublishSubject doesn't replay events. I don't think you can test PublishSubject with RxBlocking directly. You can see how it's tested here.

huy-le commented 6 years ago

@biboran Thanks, I thought that it behaves same.