diff --git a/Tests/RxCocoaTests/Observable+BindTests.swift b/Tests/RxCocoaTests/Observable+BindTests.swift index 8446d2a89..581bd74ff 100644 --- a/Tests/RxCocoaTests/Observable+BindTests.swift +++ b/Tests/RxCocoaTests/Observable+BindTests.swift @@ -152,7 +152,7 @@ extension ObservableBindTest { let relay = PublishRelay() - _ = relay.subscribe{ event in + _ = relay.subscribe { event in events.append(Recorded(time: 0, value: event)) } @@ -162,13 +162,39 @@ extension ObservableBindTest { .next(1) ]) } + + func testBindToPublishRelays() { + var events1: [Recorded>] = [] + var events2: [Recorded>] = [] + + let relay1 = PublishRelay() + let relay2 = PublishRelay() + + _ = relay1.subscribe { event in + events1.append(Recorded(time: 0, value: event)) + } + + _ = relay2.subscribe { event in + events2.append(Recorded(time: 0, value: event)) + } + + _ = Observable.just(1).bind(to: relay1, relay2) + + XCTAssertEqual(events1, [ + .next(1) + ]) + + XCTAssertEqual(events2, [ + .next(1) + ]) + } func testBindToOptionalPublishRelay() { var events: [Recorded>] = [] let relay = PublishRelay() - _ = relay.subscribe{ event in + _ = relay.subscribe { event in events.append(Recorded(time: 0, value: event)) } @@ -179,12 +205,38 @@ extension ObservableBindTest { ]) } + func testBindToOptionalPublishRelays() { + var events1: [Recorded>] = [] + var events2: [Recorded>] = [] + + let relay1 = PublishRelay() + let relay2 = PublishRelay() + + _ = relay1.subscribe { event in + events1.append(Recorded(time: 0, value: event)) + } + + _ = relay2.subscribe { event in + events2.append(Recorded(time: 0, value: event)) + } + + _ = Observable.just(1).bind(to: relay1, relay2) + + XCTAssertEqual(events1, [ + .next(1) + ]) + + XCTAssertEqual(events2, [ + .next(1) + ]) + } + func testBindToPublishRelayNoAmbiguity() { var events: [Recorded>] = [] let relay = PublishRelay() - _ = relay.subscribe{ event in + _ = relay.subscribe { event in events.append(Recorded(time: 0, value: event)) } @@ -206,6 +258,17 @@ extension ObservableBindTest { XCTAssertEqual(relay.value, 1) } + + + func testBindToBehaviorRelays() { + let relay1 = BehaviorRelay(value: 0) + let relay2 = BehaviorRelay(value: 0) + + _ = Observable.just(1).bind(to: relay1, relay2) + + XCTAssertEqual(relay1.value, 1) + XCTAssertEqual(relay2.value, 1) + } func testBindToOptionalBehaviorRelay() { let relay = BehaviorRelay(value: 0) @@ -215,6 +278,16 @@ extension ObservableBindTest { XCTAssertEqual(relay.value, 1) } + func testBindToOptionalBehaviorRelays() { + let relay1 = BehaviorRelay(value: 0) + let relay2 = BehaviorRelay(value: 0) + + _ = Observable.just(1).bind(to: relay1, relay2) + + XCTAssertEqual(relay1.value, 1) + XCTAssertEqual(relay2.value, 1) + } + func testBindToBehaviorRelayNoAmbiguity() { let relay = BehaviorRelay(value: 0)