@@ -19,60 +19,60 @@ final class ReducerTests: XCTestCase {
1919 XCTAssertEqual ( state, 1 )
2020 }
2121
22- #if canImport(RoomPlan) || (!canImport(Darwin) && swift(>=5.7))
23- func testCombine_EffectsAreMerged( ) async throws {
24- if #available( iOS 16 , macOS 13 , tvOS 16 , watchOS 9 , * ) {
25- enum Action : Equatable {
26- case increment
27- }
22+ #if canImport(RoomPlan) || (!canImport(Darwin) && swift(>=5.7))
23+ func testCombine_EffectsAreMerged( ) async throws {
24+ if #available( iOS 16 , macOS 13 , tvOS 16 , watchOS 9 , * ) {
25+ enum Action : Equatable {
26+ case increment
27+ }
2828
29- struct Delayed : ReducerProtocol {
30- typealias State = Int
29+ struct Delayed : ReducerProtocol {
30+ typealias State = Int
3131
32- @Dependency ( \. continuousClock) var clock
32+ @Dependency ( \. continuousClock) var clock
3333
34- let delay : Duration
35- let setValue : @Sendable ( ) async -> Void
34+ let delay : Duration
35+ let setValue : @Sendable ( ) async -> Void
3636
37- func reduce( into state: inout State , action: Action ) -> EffectTask < Action > {
38- state += 1
39- return . fireAndForget {
40- try await self . clock. sleep ( for: self . delay)
41- await self . setValue ( )
37+ func reduce( into state: inout State , action: Action ) -> EffectTask < Action > {
38+ state += 1
39+ return . fireAndForget {
40+ try await self . clock. sleep ( for: self . delay)
41+ await self . setValue ( )
42+ }
4243 }
4344 }
44- }
4545
46- var fastValue : Int ? = nil
47- var slowValue : Int ? = nil
46+ var fastValue : Int ? = nil
47+ var slowValue : Int ? = nil
4848
49- let store = TestStore (
50- initialState: 0 ,
51- reducer: CombineReducers {
52- Delayed ( delay: . seconds( 1 ) , setValue: { @MainActor in fastValue = 42 } )
53- Delayed ( delay: . seconds( 2 ) , setValue: { @MainActor in slowValue = 1729 } )
54- }
55- )
49+ let store = TestStore (
50+ initialState: 0 ,
51+ reducer: CombineReducers {
52+ Delayed ( delay: . seconds( 1 ) , setValue: { @MainActor in fastValue = 42 } )
53+ Delayed ( delay: . seconds( 2 ) , setValue: { @MainActor in slowValue = 1729 } )
54+ }
55+ )
5656
57- let clock = TestClock ( )
58- store. dependencies. continuousClock = clock
57+ let clock = TestClock ( )
58+ store. dependencies. continuousClock = clock
5959
60- await store. send ( . increment) {
61- $0 = 2
60+ await store. send ( . increment) {
61+ $0 = 2
62+ }
63+ // Waiting a second causes the fast effect to fire.
64+ await clock. advance ( by: . seconds( 1 ) )
65+ try await Task . sleep ( nanoseconds: NSEC_PER_SEC / 3 )
66+ XCTAssertEqual ( fastValue, 42 )
67+ XCTAssertEqual ( slowValue, nil )
68+ // Waiting one more second causes the slow effect to fire. This proves that the effects
69+ // are merged together, as opposed to concatenated.
70+ await clock. advance ( by: . seconds( 1 ) )
71+ await store. finish ( )
72+ XCTAssertEqual ( fastValue, 42 )
73+ XCTAssertEqual ( slowValue, 1729 )
6274 }
63- // Waiting a second causes the fast effect to fire.
64- await clock. advance ( by: . seconds( 1 ) )
65- try await Task . sleep ( nanoseconds: NSEC_PER_SEC / 3 )
66- XCTAssertEqual ( fastValue, 42 )
67- XCTAssertEqual ( slowValue, nil )
68- // Waiting one more second causes the slow effect to fire. This proves that the effects
69- // are merged together, as opposed to concatenated.
70- await clock. advance ( by: . seconds( 1 ) )
71- await store. finish ( )
72- XCTAssertEqual ( fastValue, 42 )
73- XCTAssertEqual ( slowValue, 1729 )
7475 }
75- }
7676 #endif
7777
7878 func testCombine( ) async {
0 commit comments