@@ -230,6 +230,36 @@ final class TestLeakingFlow: Flow {
230
230
}
231
231
}
232
232
233
+ final class TestChildLeakingFlow : Flow {
234
+ final class ChildViewController : UIViewController {
235
+ var onDeinit : ( ( ) -> Void ) ? = nil
236
+
237
+ deinit {
238
+ onDeinit ? ( )
239
+ }
240
+ }
241
+
242
+ var root : Presentable = UIViewController ( )
243
+ weak var childViewController : ChildViewController ? = nil
244
+
245
+ func navigate( to step: Step ) -> FlowContributors {
246
+ guard let step = step as? TestSteps else { return . none }
247
+
248
+ switch step {
249
+ case . one:
250
+ let viewController = ChildViewController ( )
251
+ childViewController = viewController
252
+ let flowContributor = FlowContributor . contribute (
253
+ withNextPresentable: viewController,
254
+ withNextStepper: DefaultStepper ( )
255
+ )
256
+ return . one( flowContributor: flowContributor)
257
+ default :
258
+ return . none
259
+ }
260
+ }
261
+ }
262
+
233
263
final class FlowCoordinatorTests : XCTestCase {
234
264
235
265
func testCoordinateWithOneStepper( ) {
@@ -368,6 +398,33 @@ final class FlowCoordinatorTests: XCTestCase {
368
398
369
399
XCTAssertNil ( leakingFlowReference)
370
400
}
401
+
402
+ func testChildViewControllerIsNotLeakingWhenParentFlowAllowsStepWhenDismissed( ) throws {
403
+ let exp = expectation ( description: " Flow when ready " )
404
+ let flowCoordinator = FlowCoordinator ( )
405
+ let parentFlow = TestChildLeakingFlow ( )
406
+
407
+ flowCoordinator. coordinate ( flow: parentFlow,
408
+ with: OneStepper ( withSingleStep: TestSteps . one) ,
409
+ allowStepWhenDismissed: true )
410
+
411
+ Flows . use ( parentFlow, when: . created) { ( _) in
412
+ exp. fulfill ( )
413
+ }
414
+
415
+ waitForExpectations ( timeout: 1 )
416
+
417
+ XCTAssertNotNil ( parentFlow. childViewController)
418
+
419
+ let deallocExp = expectation ( description: " Child view controller deallocated " )
420
+ parentFlow. childViewController? . onDeinit = { deallocExp. fulfill ( ) }
421
+
422
+ try XCTUnwrap ( parentFlow. childViewController) . didMove ( toParent: nil )
423
+
424
+ waitForExpectations ( timeout: 1 )
425
+
426
+ XCTAssertNil ( parentFlow. childViewController)
427
+ }
371
428
372
429
func testNavigate_executes_on_mainThread( ) {
373
430
class ThreadRecorderFlow : Flow {
0 commit comments