Skip to content

Commit d6d7ca6

Browse files
authored
Add some tests to ViewStore.send(_:while:) and ViewStore.suspend. (#674)
1 parent d4c0ff3 commit d6d7ca6

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

.swiftpm/xcode/xcshareddata/xcschemes/swift-composable-architecture-benchmark.xcscheme

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
2929
shouldUseLaunchSchemeArgsEnv = "YES">
3030
<Testables>
31+
<TestableReference
32+
skipped = "NO">
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "ComposableArchitectureTests"
36+
BuildableName = "ComposableArchitectureTests"
37+
BlueprintName = "ComposableArchitectureTests"
38+
ReferencedContainer = "container:">
39+
</BuildableReference>
40+
</TestableReference>
3141
</Testables>
3242
</TestAction>
3343
<LaunchAction

Tests/ComposableArchitectureTests/ViewStoreTests.swift

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,64 @@ final class ViewStoreTests: XCTestCase {
136136
ViewStore(store).send(())
137137
XCTAssertEqual(results, [0, 1])
138138
}
139+
140+
#if compiler(>=5.5)
141+
@available(iOS 15, *)
142+
func testSendWhile() async {
143+
enum Action {
144+
case response
145+
case tapped
146+
}
147+
let reducer = Reducer<Bool, Action, Void> { state, action, environment in
148+
switch action {
149+
case .response:
150+
state = false
151+
return .none
152+
case .tapped:
153+
state = true
154+
return Effect(value: .response)
155+
.receive(on: DispatchQueue.main)
156+
.eraseToEffect()
157+
}
158+
}
159+
160+
let store = Store(initialState: false, reducer: reducer, environment: ())
161+
let viewStore = ViewStore(store)
162+
163+
XCTAssertEqual(viewStore.state, false)
164+
await viewStore.send(.tapped, while: { $0 })
165+
XCTAssertEqual(viewStore.state, false)
166+
}
167+
168+
@available(iOS 15, *)
169+
func testSuspend() async {
170+
enum Action {
171+
case response
172+
case tapped
173+
}
174+
let reducer = Reducer<Bool, Action, Void> { state, action, environment in
175+
switch action {
176+
case .response:
177+
state = false
178+
return .none
179+
case .tapped:
180+
state = true
181+
return Effect(value: .response)
182+
.receive(on: DispatchQueue.main)
183+
.eraseToEffect()
184+
}
185+
}
186+
187+
let store = Store(initialState: false, reducer: reducer, environment: ())
188+
let viewStore = ViewStore(store)
189+
190+
XCTAssertEqual(viewStore.state, false)
191+
viewStore.send(.tapped)
192+
XCTAssertEqual(viewStore.state, true)
193+
await viewStore.suspend(while: { $0 })
194+
XCTAssertEqual(viewStore.state, false)
195+
}
196+
#endif
139197
}
140198

141199
private struct State: Equatable {

0 commit comments

Comments
 (0)