@@ -136,6 +136,64 @@ final class ViewStoreTests: XCTestCase {
136136 ViewStore ( store) . send ( ( ) )
137137 XCTAssertEqual ( results, [ 0 , 1 ] )
138138 }
139+
140+ #if compiler(>=5.5)
141+ @available ( iOS 15 , * )
142+ func testSendWhile( ) async {
143+ enum Action {
144+ case response
145+ case tapped
146+ }
147+ let reducer = Reducer < Bool , Action , Void > { state, action, environment in
148+ switch action {
149+ case . response:
150+ state = false
151+ return . none
152+ case . tapped:
153+ state = true
154+ return Effect ( value: . response)
155+ . receive ( on: DispatchQueue . main)
156+ . eraseToEffect ( )
157+ }
158+ }
159+
160+ let store = Store ( initialState: false , reducer: reducer, environment: ( ) )
161+ let viewStore = ViewStore ( store)
162+
163+ XCTAssertEqual ( viewStore. state, false )
164+ await viewStore. send ( . tapped, while: { $0 } )
165+ XCTAssertEqual ( viewStore. state, false )
166+ }
167+
168+ @available ( iOS 15 , * )
169+ func testSuspend( ) async {
170+ enum Action {
171+ case response
172+ case tapped
173+ }
174+ let reducer = Reducer < Bool , Action , Void > { state, action, environment in
175+ switch action {
176+ case . response:
177+ state = false
178+ return . none
179+ case . tapped:
180+ state = true
181+ return Effect ( value: . response)
182+ . receive ( on: DispatchQueue . main)
183+ . eraseToEffect ( )
184+ }
185+ }
186+
187+ let store = Store ( initialState: false , reducer: reducer, environment: ( ) )
188+ let viewStore = ViewStore ( store)
189+
190+ XCTAssertEqual ( viewStore. state, false )
191+ viewStore. send ( . tapped)
192+ XCTAssertEqual ( viewStore. state, true )
193+ await viewStore. suspend ( while: { $0 } )
194+ XCTAssertEqual ( viewStore. state, false )
195+ }
196+ #endif
139197}
140198
141199private struct State : Equatable {
0 commit comments