Skip to content

Commit 0c22607

Browse files
authored
Swift bug workaround for TestStore completion (#2923)
* Swift bug workaround for `TestStore` completion * fix
1 parent 5ab136f commit 0c22607

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

Sources/ComposableArchitecture/TestStore.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,17 @@ public final class TestStore<State, Action> {
499499
///
500500
/// - Parameters:
501501
/// - initialState: The state the feature starts in.
502-
/// - reducer: The reducer that powers the runtime of the feature.
502+
/// - reducer: The reducer that powers the runtime of the feature. Unlike
503+
/// ``Store/init(initialState:reducer:withDependencies:)``, this is _not_ a builder closure
504+
/// due to a [Swift bug](https://github.com/apple/swift/issues/72399) that is more likely to
505+
/// affect test store initialization. If you must compose multiple reducers in this closure,
506+
/// wrap them in ``CombineReducers``.
503507
/// - prepareDependencies: A closure that can be used to override dependencies that will be
504508
/// accessed during the test. These dependencies will be used when producing the initial
505509
/// state.
506510
public init<R: Reducer>(
507-
initialState: @autoclosure () -> R.State,
508-
@ReducerBuilder<State, Action> reducer: () -> R,
511+
initialState: @autoclosure () -> State,
512+
reducer: () -> R,
509513
withDependencies prepareDependencies: (inout DependencyValues) -> Void = { _ in
510514
},
511515
file: StaticString = #file,

Tests/ComposableArchitectureTests/ReducerTests.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@
4545
let clock = TestClock()
4646

4747
let store = TestStore(initialState: 0) {
48-
Feature_testCombine_EffectsAreMerged(
49-
delay: .seconds(1), setValue: { @MainActor in fastValue = 42 })
50-
Feature_testCombine_EffectsAreMerged(
51-
delay: .seconds(2), setValue: { @MainActor in slowValue = 1729 })
48+
CombineReducers {
49+
Feature_testCombine_EffectsAreMerged(
50+
delay: .seconds(1), setValue: { @MainActor in fastValue = 42 })
51+
Feature_testCombine_EffectsAreMerged(
52+
delay: .seconds(2), setValue: { @MainActor in slowValue = 1729 })
53+
}
5254
} withDependencies: {
5355
$0.continuousClock = clock
5456
}
@@ -90,8 +92,10 @@
9092
var second = false
9193

9294
let store = TestStore(initialState: 0) {
93-
Feature_testCombine(effect: { @MainActor in first = true })
94-
Feature_testCombine(effect: { @MainActor in second = true })
95+
CombineReducers {
96+
Feature_testCombine(effect: { @MainActor in first = true })
97+
Feature_testCombine(effect: { @MainActor in second = true })
98+
}
9599
}
96100

97101
await store

0 commit comments

Comments
 (0)