@@ -11,6 +11,9 @@ public final class TestStore<Reducer: ReducerProtocol> where Reducer.Action: Equ
1111 /// The running state container.
1212 var runningContainer : StateContainer < Reducer . Target > ?
1313
14+ /// The running tasks
15+ var runningTasks : [ SendTask ] = [ ]
16+
1417 /// An array of tested actions.
1518 var testedActions : [ ActionTransition < Reducer > ] = [ ]
1619
@@ -62,6 +65,18 @@ public final class TestStore<Reducer: ReducerProtocol> where Reducer.Action: Equ
6265 }
6366 }
6467
68+ /// Wait for all of the TestStore's remaining SendTasks to complete.
69+ public func waitForAll( ) async {
70+ await withTaskGroup ( of: Void . self) { group in
71+ for task in runningTasks {
72+ group. addTask {
73+ await task. wait ( )
74+ }
75+ }
76+ await group. waitForAll ( )
77+ }
78+ }
79+
6580 /// Asserts an action was received from an effect and asserts how the state changes.
6681 ///
6782 /// - Parameters:
@@ -210,6 +225,7 @@ public final class TestStore<Reducer: ReducerProtocol> where Reducer.Action: Equ
210225 let actualContainer = expectedContainer. copy ( )
211226
212227 let sendTask = target. store. sendIfNeeded ( action)
228+ runningTasks. append ( sendTask)
213229
214230 expected ? ( actualContainer)
215231
@@ -241,6 +257,7 @@ public final class TestStore<Reducer: ReducerProtocol> where Reducer.Action: Equ
241257 let actualContainer = expectedContainer. copy ( )
242258
243259 let sendTask = target. store. sendIfNeeded ( action)
260+ runningTasks. append ( sendTask)
244261
245262 expected ? ( actualContainer)
246263
@@ -273,6 +290,7 @@ public final class TestStore<Reducer: ReducerProtocol> where Reducer.Action: Equ
273290 let actualContainer = expectedContainer. copy ( )
274291
275292 let sendTask = target. store. sendIfNeeded ( action)
293+ runningTasks. append ( sendTask)
276294
277295 expected ? ( actualContainer)
278296
@@ -304,6 +322,7 @@ public final class TestStore<Reducer: ReducerProtocol> where Reducer.Action: Equ
304322 let actualContainer = expectedContainer. copy ( )
305323
306324 let sendTask = target. store. sendIfNeeded ( action)
325+ runningTasks. append ( sendTask)
307326
308327 expected ? ( actualContainer)
309328
0 commit comments