Skip to content

Commit e0334a0

Browse files
authored
Test to confirm dependencies are also controlled in receive's updateExpectingResult closure (#1644)
1 parent f444001 commit e0334a0

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
@@ -275,9 +275,21 @@ final class TestStoreTests: XCTestCase {
275275
self.date = now
276276
}
277277
}
278-
func reduce(into state: inout State, action: Void) -> EffectTask<Void> {
279-
state.count += 1
280-
return .none
278+
enum Action: Equatable {
279+
case tap
280+
case response(Int)
281+
}
282+
@Dependency(\.date.now) var now: Date
283+
func reduce(into state: inout State, action: Action) -> EffectTask<Action> {
284+
switch action {
285+
case .tap:
286+
state.count += 1
287+
return .task { .response(42) }
288+
case let .response(number):
289+
state.count = number
290+
state.date = now
291+
return .none
292+
}
281293
}
282294
}
283295

@@ -288,10 +300,15 @@ final class TestStoreTests: XCTestCase {
288300
$0.date = .constant(Date(timeIntervalSince1970: 1_234_567_890))
289301
}
290302

291-
await store.send(()) {
303+
await store.send(.tap) {
292304
@Dependency(\.date.now) var now: Date
293305
$0.count = 1
294306
$0.date = now
295307
}
308+
await store.receive(.response(42)) {
309+
@Dependency(\.date.now) var now: Date
310+
$0.count = 42
311+
$0.date = now
312+
}
296313
}
297314
}

0 commit comments

Comments
 (0)