@@ -207,6 +207,28 @@ final class TestDismissedFlow: Flow {
207207 }
208208}
209209
210+ final class TestLeakingFlow : Flow {
211+ var root : Presentable = UIViewController ( )
212+
213+ var rxDismissed : Single < Void > { rxDismissedRelay. take ( 1 ) . asSingle ( ) }
214+ let rxDismissedRelay = PublishRelay < Void > ( )
215+
216+ func navigate( to step: Step ) -> FlowContributors {
217+ guard let step = step as? TestSteps else { return . none }
218+
219+ switch step {
220+ case . one:
221+ let flowContributor = FlowContributor . contribute (
222+ withNextPresentable: UIViewController ( ) ,
223+ withNextStepper: DefaultStepper ( )
224+ )
225+ return . one( flowContributor: flowContributor)
226+ default :
227+ return . none
228+ }
229+ }
230+ }
231+
210232final class FlowCoordinatorTests : XCTestCase {
211233
212234 func testCoordinateWithOneStepper( ) {
@@ -320,6 +342,31 @@ final class FlowCoordinatorTests: XCTestCase {
320342 let recordedSteps = try ? dismissedFlow. recordedSteps. take ( 3 ) . toBlocking ( ) . toArray ( )
321343 XCTAssertEqual ( recordedSteps, [ . one, . two, . three] )
322344 }
345+
346+ func testFlowIsNotLeakingWhenHasOneStep( ) throws {
347+ weak var leakingFlowReference : TestLeakingFlow ?
348+ let exp = expectation ( description: " Flow when ready " )
349+ let flowCoordinator = FlowCoordinator ( )
350+
351+ withExtendedLifetime ( TestLeakingFlow ( ) ) { leakingFlow in
352+ leakingFlowReference = leakingFlow
353+
354+ flowCoordinator. coordinate ( flow: leakingFlow,
355+ with: OneStepper ( withSingleStep: TestSteps . one) )
356+
357+ Flows . use ( leakingFlow, when: . created) { ( _) in
358+ exp. fulfill ( )
359+ }
360+ }
361+
362+ waitForExpectations ( timeout: 1 )
363+
364+ XCTAssertNotNil ( leakingFlowReference)
365+
366+ try XCTUnwrap ( leakingFlowReference) . rxDismissedRelay. accept ( Void ( ) )
367+
368+ XCTAssertNil ( leakingFlowReference)
369+ }
323370}
324371
325372#endif
0 commit comments