Skip to content

Commit 4426228

Browse files
craymentp4checo
authored andcommitted
Test to confirm dependencies are also controlled in receive's updateExpectingResult closure (#1644)
(cherry picked from commit e0334a08b8c53e00875ae1cd718ede5b6dbb8c0a)
1 parent df6fdb1 commit 4426228

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

Tests/ComposableArchitectureTests/TestStoreTests.swift

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,21 @@ final class TestStoreTests: XCTestCase {
276276
self.date = now
277277
}
278278
}
279-
func reduce(into state: inout State, action: Void) -> EffectTask<Void> {
280-
state.count += 1
281-
return .none
279+
enum Action: Equatable {
280+
case tap
281+
case response(Int)
282+
}
283+
@Dependency(\.date.now) var now: Date
284+
func reduce(into state: inout State, action: Action) -> EffectTask<Action> {
285+
switch action {
286+
case .tap:
287+
state.count += 1
288+
return .task { .response(42) }
289+
case let .response(number):
290+
state.count = number
291+
state.date = now
292+
return .none
293+
}
282294
}
283295
}
284296

@@ -289,11 +301,16 @@ final class TestStoreTests: XCTestCase {
289301
$0.date = .constant(Date(timeIntervalSince1970: 1_234_567_890))
290302
}
291303

292-
await store.send(()) {
304+
await store.send(.tap) {
293305
@Dependency(\.date.now) var now: Date
294306
$0.count = 1
295307
$0.date = now
296308
}
309+
await store.receive(.response(42)) {
310+
@Dependency(\.date.now) var now: Date
311+
$0.count = 42
312+
$0.date = now
313+
}
297314
}
298315
}
299316
#endif

0 commit comments

Comments
 (0)