Skip to content

Commit

Permalink
Add tests that RxSwiftCommunity#216 reproduces
Browse files Browse the repository at this point in the history
  • Loading branch information
Econa77 committed Apr 13, 2021
1 parent 2546b57 commit 8b96f4c
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions Tests/ActionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class ActionTests: QuickSpec {
let completions = scheduler.createObserver(Void.self)
action.completions.bind(to: completions).disposed(by: disposeBag)
scheduler.start()
expect(completions.events.contains { $0.time == 10}).to(beTrue())
expect(completions.events.contains { $0.time == 20}).to(beTrue())
expect(completions.events.contains { $0.time == 10 }).to(beTrue())
expect(completions.events.contains { $0.time == 20 }).to(beTrue())
}
}

Expand Down Expand Up @@ -520,6 +520,49 @@ class ActionTests: QuickSpec {
expect(executionObservables.events.count).to(match(1))
}
}

fcontext("subscribe elements while executing") {
var trigger: PublishSubject<Void>!

beforeEach {
trigger = PublishSubject<Void>()
action = Action { Observable.just($0).sample(trigger) }

action.executionObservables
.bind(to: executionObservables)
.disposed(by: disposeBag)

scheduler.scheduleAt(10) {
Observable.just("a")
.bind(to: action.inputs)
.disposed(by: disposeBag)
}

scheduler.scheduleAt(20) {
action.elements
.bind(to: element)
.disposed(by: disposeBag)
}

scheduler.scheduleAt(30) {
#if swift(>=3.2)
trigger.onNext(())
#else
trigger.onNext()
#endif
}

scheduler.start()
}

it("elements receives value") {
expect(element.events).to(match(Recorded.events([.next(30, "a")])))
}

it("executes once") {
expect(executionObservables.events.count).to(match(1))
}
}
}
}
}
Expand Down

0 comments on commit 8b96f4c

Please sign in to comment.