You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reactors are not easily testable, because they do not use the same queue as the tests (see Reactor.swift)
In SwiftUIReactor, simple reactors cannot be tested synchronously (test fails):
import XCTest
import Combine
@testable import SwiftUIReactor
finalclassTestConcurrency:XCTestCase{func testCountingUp(){
for exponent in 0..<8{letreactor=CountingReactor()let_amount:Double=pow(10,Double(exponent))letamount=Int(_amount)print("Testing", amount)
for _ in 0..<amount {
reactor.action(.countUp)}XCTAssertEqual(reactor.state.currentCount, amount)}}}finalclassCountingReactor:Reactor{enumAction{case countUp
}enumMutation{case countUp
}structState{varcurrentCount:Int}varcancellables:Set<AnyCancellable>=[]varstate:State=State(currentCount:0)func mutate(action:Action)->AnyPublisher<Mutation,Never>{returnJust(Mutation.countUp).eraseToAnyPublisher()}func reduce(mutation:Mutation){varnewState= state
newState.currentCount +=1
state = newState
}}
In ReactorKit this is circumvented via the CurrentThreadScheduler.instance, see here.
Simple reactors can, therefore, be tested synchronously (test succeeds):
import XCTest
import RxSwift
@testable import ReactorKit
finalclassTestConcurrency:XCTestCase{func testCountingUp(){
for exponent in 0...5{letreactor=CountingReactor()let_amount:Double=pow(10,Double(exponent))letamount=Int(_amount)print("Testing", amount)
for _ in 0..<amount {
reactor.action.onNext(.countUp)}XCTAssertEqual(reactor.currentState.currentCount, amount)}}}finalclassCountingReactor:Reactor{enumAction{case countUp
}structState{varcurrentCount:Int}letinitialState=State(currentCount:0)func mutate(action:Action)->Observable<Action>{return.just(Mutation.countUp)}func reduce(state:State, mutation:Action)->State{varnewState= state
newState.currentCount +=1return newState
}}
The text was updated successfully, but these errors were encountered:
Reactors are not easily testable, because they do not use the same queue as the tests (see Reactor.swift)
In SwiftUIReactor, simple reactors cannot be tested synchronously (test fails):
In ReactorKit this is circumvented via the
CurrentThreadScheduler.instance
, see here.Simple reactors can, therefore, be tested synchronously (test succeeds):
The text was updated successfully, but these errors were encountered: