Skip to content

Commit 7557b87

Browse files
committed
Add test for uncached stores.
1 parent f1b426d commit 7557b87

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Tests/ComposableArchitectureTests/StoreLifetimeTests.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,25 @@ final class StoreLifetimeTests: BaseTCATestCase {
129129
await self.fulfillment(of: [effectFinished], timeout: 0.5)
130130
}
131131
#endif
132+
133+
@MainActor
134+
@available(*, deprecated)
135+
func testUnCachedStores() async {
136+
Logger.shared.isEnabled = true
137+
let clock = TestClock()
138+
let store = Store(initialState: Parent.State()) {
139+
Parent()
140+
} withDependencies: {
141+
$0.continuousClock = clock
142+
}
143+
do {
144+
let child = store.scope(state: { $0.child }, action: { .child($0) })
145+
child.send(.start)
146+
XCTAssertEqual(store.withState(\.child.count), 1)
147+
}
148+
await clock.run()
149+
XCTAssertEqual(store.withState(\.child.count), 2)
150+
}
132151
}
133152

134153
@Reducer
@@ -138,13 +157,25 @@ private struct Child {
138157
}
139158
enum Action {
140159
case tap
160+
case start
161+
case response
141162
}
163+
@Dependency(\.continuousClock) var clock
142164
var body: some ReducerOf<Self> {
143165
Reduce { state, action in
144166
switch action {
145167
case .tap:
146168
state.count += 1
147169
return .none
170+
case .start:
171+
state.count += 1
172+
return .run { send in
173+
try await clock.sleep(for: .seconds(0))
174+
await send(.response)
175+
}
176+
case .response:
177+
state.count += 1
178+
return .none
148179
}
149180
}
150181
}

0 commit comments

Comments
 (0)