@@ -100,29 +100,29 @@ final class ViewStoreTests: XCTestCase {
100
100
101
101
#if canImport(Combine)
102
102
@available ( iOS 13 . 0 , OSX 10 . 15 , tvOS 13 . 0 , watchOS 6 . 0 , * )
103
- func testWillSet( ) {
103
+ func testWillSet( ) {
104
104
var cancellables : Set < AnyCancellable > = [ ]
105
105
106
- let reducer = Reducer < Int , Void , Void > { count, _, _ in
107
- count += 1
108
- return . none
109
- }
106
+ let reducer = Reducer < Int , Void , Void > { count, _, _ in
107
+ count += 1
108
+ return . none
109
+ }
110
110
111
- let store = Store ( initialState: 0 , reducer: reducer, environment: ( ) )
112
- let viewStore = ViewStore ( store)
111
+ let store = Store ( initialState: 0 , reducer: reducer, environment: ( ) )
112
+ let viewStore = ViewStore ( store)
113
113
114
- var results : [ Int ] = [ ]
114
+ var results : [ Int ] = [ ]
115
115
116
- viewStore. objectWillChange
117
- . sink { _ in results. append ( viewStore. state) }
116
+ viewStore. objectWillChange
117
+ . sink { _ in results. append ( viewStore. state) }
118
118
. store ( in: & cancellables)
119
119
120
- viewStore. send ( ( ) )
121
- viewStore. send ( ( ) )
122
- viewStore. send ( ( ) )
120
+ viewStore. send ( ( ) )
121
+ viewStore. send ( ( ) )
122
+ viewStore. send ( ( ) )
123
123
124
- XCTAssertEqual ( [ 0 , 1 , 2 ] , results)
125
- }
124
+ XCTAssertEqual ( [ 0 , 1 , 2 ] , results)
125
+ }
126
126
#endif
127
127
128
128
// disabled as the fix for this would be onerous with
@@ -145,61 +145,73 @@ final class ViewStoreTests: XCTestCase {
145
145
}
146
146
147
147
#if compiler(>=5.5)
148
- @available ( iOS 15 , macOS 12 , tvOS 15 , watchOS 8 , * )
149
- func testSendWhile( ) async {
150
- enum Action {
151
- case response
152
- case tapped
153
- }
154
- let reducer = Reducer < Bool , Action , Void > { state, action, environment in
155
- switch action {
156
- case . response:
157
- state = false
158
- return . none
159
- case . tapped:
160
- state = true
161
- return Effect ( value: . response)
148
+ func testSendWhile( ) {
149
+ guard #available( iOS 15 , macOS 12 , tvOS 15 , watchOS 8 , * ) else { return }
150
+
151
+ let expectation = self . expectation ( description: " await " )
152
+ Task { @MainActor in
153
+ enum Action {
154
+ case response
155
+ case tapped
156
+ }
157
+ let reducer = Reducer < Bool , Action , Void > { state, action, environment in
158
+ switch action {
159
+ case . response:
160
+ state = false
161
+ return . none
162
+ case . tapped:
163
+ state = true
164
+ return Effect ( value: . response)
162
165
. start ( on: QueueScheduler . main)
163
166
. observe ( on: QueueScheduler . main)
167
+ }
164
168
}
165
- }
166
-
167
- let store = Store ( initialState: false , reducer: reducer, environment: ( ) )
168
- let viewStore = ViewStore ( store)
169
169
170
- XCTAssertEqual ( viewStore. state, false )
171
- await viewStore. send ( . tapped, while: { $0 } )
172
- XCTAssertEqual ( viewStore. state, false )
173
- }
170
+ let store = Store ( initialState: false , reducer: reducer, environment: ( ) )
171
+ let viewStore = ViewStore ( store)
174
172
175
- @available ( iOS 15 , macOS 12 , tvOS 15 , watchOS 8 , * )
176
- func testSuspend( ) async {
177
- enum Action {
178
- case response
179
- case tapped
173
+ XCTAssertEqual ( viewStore. state, false )
174
+ await viewStore. send ( . tapped, while: { $0 } )
175
+ XCTAssertEqual ( viewStore. state, false )
176
+ expectation. fulfill ( )
177
+ }
178
+ self . wait ( for: [ expectation] , timeout: 1 )
180
179
}
181
- let reducer = Reducer < Bool , Action , Void > { state, action, environment in
182
- switch action {
183
- case . response:
184
- state = false
185
- return . none
186
- case . tapped:
187
- state = true
188
- return Effect ( value: . response)
180
+
181
+ func testSuspend( ) {
182
+ guard #available( iOS 15 , macOS 12 , tvOS 15 , watchOS 8 , * ) else { return }
183
+
184
+ let expectation = self . expectation ( description: " await " )
185
+ Task { @MainActor in
186
+ enum Action {
187
+ case response
188
+ case tapped
189
+ }
190
+ let reducer = Reducer < Bool , Action , Void > { state, action, environment in
191
+ switch action {
192
+ case . response:
193
+ state = false
194
+ return . none
195
+ case . tapped:
196
+ state = true
197
+ return Effect ( value: . response)
189
198
. start ( on: QueueScheduler . main)
190
199
. observe ( on: QueueScheduler . main)
200
+ }
191
201
}
192
- }
193
202
194
- let store = Store ( initialState: false , reducer: reducer, environment: ( ) )
195
- let viewStore = ViewStore ( store)
203
+ let store = Store ( initialState: false , reducer: reducer, environment: ( ) )
204
+ let viewStore = ViewStore ( store)
196
205
197
- XCTAssertEqual ( viewStore. state, false )
198
- viewStore. send ( . tapped)
199
- XCTAssertEqual ( viewStore. state, true )
200
- await viewStore. suspend ( while: { $0 } )
201
- XCTAssertEqual ( viewStore. state, false )
202
- }
206
+ XCTAssertEqual ( viewStore. state, false )
207
+ viewStore. send ( . tapped)
208
+ XCTAssertEqual ( viewStore. state, true )
209
+ await viewStore. suspend ( while: { $0 } )
210
+ XCTAssertEqual ( viewStore. state, false )
211
+ expectation. fulfill ( )
212
+ }
213
+ self . wait ( for: [ expectation] , timeout: 1 )
214
+ }
203
215
#endif
204
216
}
205
217
0 commit comments