diff --git a/Tests/ComposableArchitectureTests/StoreTests.swift b/Tests/ComposableArchitectureTests/StoreTests.swift index 50037cd87877..7ef9bccebecd 100644 --- a/Tests/ComposableArchitectureTests/StoreTests.swift +++ b/Tests/ComposableArchitectureTests/StoreTests.swift @@ -2,6 +2,10 @@ @_spi(Internals) import ComposableArchitecture import XCTest +#if canImport(Testing) + import Testing +#endif + final class StoreTests: BaseTCATestCase { var cancellables: Set = [] @@ -1172,6 +1176,53 @@ final class StoreTests: BaseTCATestCase { } } +#if canImport(Testing) + @Suite + struct ModernStoreTests { + @Reducer + fileprivate struct TaskTreeFeature { + let clock: TestClock + @ObservableState + struct State { var count = 0 } + enum Action { case tap, response1, response2 } + var body: some ReducerOf { + Reduce { state, action in + switch action { + case .tap: + return Effect.run { send in + await send(.response1) + } + case .response1: + state.count = 42 + return Effect.run { send in + try await clock.sleep(for: .seconds(1)) + await send(.response2) + } + case .response2: + state.count = 1729 + return .none + } + } + } + } + + @MainActor + @Test + func cancellation() async throws { + let clock = TestClock() + let store = Store(initialState: TaskTreeFeature.State()) { TaskTreeFeature(clock: clock) } + let task = store.send(.tap) + try await Task.sleep(for: .seconds(0.1)) + #expect(store.count == 42) + task.cancel() + await clock.run() + withKnownIssue("Cancelling the root effect should not cancel the child effects.") { + #expect(store.count == 1729) + } + } + } +#endif + private struct Count: TestDependencyKey { var value: Int static let liveValue = Count(value: 0)