Skip to content

Commit

Permalink
Add tests for bind to multiple relays
Browse files Browse the repository at this point in the history
  • Loading branch information
freak4pc committed Apr 9, 2019
1 parent 1a630a6 commit ba5cb7a
Showing 1 changed file with 76 additions and 3 deletions.
79 changes: 76 additions & 3 deletions Tests/RxCocoaTests/Observable+BindTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ extension ObservableBindTest {

let relay = PublishRelay<Int>()

_ = relay.subscribe{ event in
_ = relay.subscribe { event in
events.append(Recorded(time: 0, value: event))
}

Expand All @@ -162,13 +162,39 @@ extension ObservableBindTest {
.next(1)
])
}

func testBindToPublishRelays() {
var events1: [Recorded<Event<Int>>] = []
var events2: [Recorded<Event<Int>>] = []

let relay1 = PublishRelay<Int>()
let relay2 = PublishRelay<Int>()

_ = 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<Event<Int?>>] = []

let relay = PublishRelay<Int?>()

_ = relay.subscribe{ event in
_ = relay.subscribe { event in
events.append(Recorded(time: 0, value: event))
}

Expand All @@ -179,12 +205,38 @@ extension ObservableBindTest {
])
}

func testBindToOptionalPublishRelays() {
var events1: [Recorded<Event<Int?>>] = []
var events2: [Recorded<Event<Int?>>] = []

let relay1 = PublishRelay<Int?>()
let relay2 = PublishRelay<Int?>()

_ = 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<Event<Int?>>] = []

let relay = PublishRelay<Int?>()

_ = relay.subscribe{ event in
_ = relay.subscribe { event in
events.append(Recorded(time: 0, value: event))
}

Expand All @@ -206,6 +258,17 @@ extension ObservableBindTest {

XCTAssertEqual(relay.value, 1)
}


func testBindToBehaviorRelays() {
let relay1 = BehaviorRelay<Int>(value: 0)
let relay2 = BehaviorRelay<Int>(value: 0)

_ = Observable.just(1).bind(to: relay1, relay2)

XCTAssertEqual(relay1.value, 1)
XCTAssertEqual(relay2.value, 1)
}

func testBindToOptionalBehaviorRelay() {
let relay = BehaviorRelay<Int?>(value: 0)
Expand All @@ -215,6 +278,16 @@ extension ObservableBindTest {
XCTAssertEqual(relay.value, 1)
}

func testBindToOptionalBehaviorRelays() {
let relay1 = BehaviorRelay<Int?>(value: 0)
let relay2 = BehaviorRelay<Int?>(value: 0)

_ = Observable.just(1).bind(to: relay1, relay2)

XCTAssertEqual(relay1.value, 1)
XCTAssertEqual(relay2.value, 1)
}

func testBindToBehaviorRelayNoAmbiguity() {
let relay = BehaviorRelay<Int?>(value: 0)

Expand Down

0 comments on commit ba5cb7a

Please sign in to comment.