@@ -98,17 +98,12 @@ final class ReducerTests: XCTestCase {
9898
9999 func testDependencies( ) async {
100100 let testStore = TestView (
101- store: Store (
102- reducer: withDependencies {
103- $0. continuousClock = ImmediateClock ( )
104- } operation: {
105- TestReducer ( )
106- } ,
101+ store: . init(
102+ reducer: TestReducer ( ) . dependency ( \. test, value: . init { } ) ,
107103 initialReducerState: . init( )
108104 )
109105 ) . testStore ( states: . init( ) )
110-
111- await testStore. send ( . runEffectWithDependencies)
106+ await testStore. send ( . testDependencies)
112107 await testStore. receive ( . increment) {
113108 $0. count = 1
114109 }
@@ -134,6 +129,24 @@ final class ReducerTests: XCTestCase {
134129 }
135130}
136131
132+ struct TestDependency : DependencyKey {
133+ public var asyncThrows : @Sendable ( ) async throws -> Void
134+
135+ public init ( asyncThrows: @Sendable @escaping ( ) async throws -> Void ) {
136+ self . asyncThrows = asyncThrows
137+ }
138+
139+ public static let liveValue : TestDependency = . init( asyncThrows: { throw CancellationError ( ) } )
140+ public static let testValue : TestDependency = . init( asyncThrows: { } )
141+ }
142+
143+ extension DependencyValues {
144+ var test : TestDependency {
145+ get { self [ TestDependency . self] }
146+ set { self [ TestDependency . self] = newValue }
147+ }
148+ }
149+
137150private struct TestReducer : ReducerProtocol {
138151 struct ReducerState : Equatable {
139152 var count = 0
@@ -157,9 +170,11 @@ private struct TestReducer: ReducerProtocol {
157170 case invokeDecrement
158171 case send
159172 case runEffectWithDependencies
173+ case testDependencies
160174 }
161175
162176 @Dependency ( \. continuousClock) private var clock
177+ @Dependency ( \. test) var test
163178
164179 func reduce( into state: StateContainer < TestView > , action: ReducerAction ) -> SideEffect < Self > {
165180 switch action {
@@ -218,6 +233,12 @@ private struct TestReducer: ReducerProtocol {
218233 try await clock. sleep ( for: . seconds( 1 ) )
219234 await send ( . increment)
220235 }
236+
237+ case . testDependencies:
238+ return . run { send in
239+ try await test. asyncThrows ( )
240+ await send ( . increment)
241+ }
221242 }
222243 }
223244}
@@ -235,3 +256,27 @@ private struct TestView: View {
235256 EmptyView ( )
236257 }
237258}
259+
260+ private struct MyReducer : ReducerProtocol {
261+ enum Action {
262+ case hoge
263+ }
264+
265+ func reduce( into state: StateContainer < MyView > , action: Action ) -> SideEffect < MyReducer > {
266+ . none
267+ }
268+ }
269+
270+ @ScopeState
271+ private struct MyView : View {
272+ @State var count = 0
273+ let store : Store < MyReducer >
274+
275+ init ( store: Store < MyReducer > = Store ( reducer: MyReducer ( ) ) ) {
276+ self . store = store
277+ }
278+
279+ var body : some View {
280+ EmptyView ( )
281+ }
282+ }
0 commit comments