Skip to content

Commit b6efb27

Browse files
authored
Test store changes (#2236)
* wip * Minor test store improvements
1 parent bf6b735 commit b6efb27

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

Sources/ComposableArchitecture/Effect.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ extension EffectPublisher where Failure == Never {
150150
/// - Returns: An effect wrapping the given asynchronous work.
151151
public static func run(
152152
priority: TaskPriority? = nil,
153-
operation: @escaping @Sendable (Send<Action>) async throws -> Void,
154-
catch handler: (@Sendable (Error, Send<Action>) async -> Void)? = nil,
153+
operation: @escaping @Sendable (_ send: Send<Action>) async throws -> Void,
154+
catch handler: (@Sendable (_ error: Error, _ send: Send<Action>) async -> Void)? = nil,
155155
fileID: StaticString = #fileID,
156156
line: UInt = #line
157157
) -> Self {

Sources/ComposableArchitecture/TestStore.swift

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,27 +1948,30 @@ extension TestStore where ScopedState: Equatable {
19481948

19491949
let (receivedAction, state) = self.reducer.receivedActions.removeFirst()
19501950
if !predicate(receivedAction) {
1951+
let receivedActionLater = self.reducer.receivedActions
1952+
.contains(where: { action, _ in predicate(receivedAction) })
19511953
XCTFailHelper(
19521954
"""
1953-
Received unexpected action: …
1955+
Received unexpected action\(receivedActionLater ? " before this one" : ""): …
19541956
19551957
\(unexpectedActionDescription(receivedAction))
19561958
""",
19571959
file: file,
19581960
line: line
19591961
)
1960-
}
1961-
let expectedState = self.toScopedState(self.state)
1962-
do {
1963-
try self.expectedStateShouldMatch(
1964-
expected: expectedState,
1965-
actual: self.toScopedState(state),
1966-
updateStateToExpectedResult: updateStateToExpectedResult,
1967-
file: file,
1968-
line: line
1969-
)
1970-
} catch {
1971-
XCTFail("Threw error: \(error)", file: file, line: line)
1962+
} else {
1963+
let expectedState = self.toScopedState(self.state)
1964+
do {
1965+
try self.expectedStateShouldMatch(
1966+
expected: expectedState,
1967+
actual: self.toScopedState(state),
1968+
updateStateToExpectedResult: updateStateToExpectedResult,
1969+
file: file,
1970+
line: line
1971+
)
1972+
} catch {
1973+
XCTFail("Threw error: \(error)", file: file, line: line)
1974+
}
19721975
}
19731976
self.reducer.state = state
19741977
if "\(self.file)" == "\(file)" {
@@ -2025,7 +2028,8 @@ extension TestStore where ScopedState: Equatable {
20252028
}
20262029
XCTFail(
20272030
"""
2028-
Expected to receive \(self.exhaustivity == .on ? "an action" : "a matching action"), but received none\
2031+
Expected to receive \(self.exhaustivity == .on ? "an action" : "a matching action"), but \
2032+
received none\
20292033
\(nanoseconds > 0 ? " after \(Double(nanoseconds)/Double(NSEC_PER_SEC)) seconds" : "").
20302034
20312035
\(suggestion)

Tests/ComposableArchitectureTests/TestStoreFailureTests.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,11 @@
221221
let store = TestStore(initialState: 0) {
222222
Reduce<Int, Action> { state, action in
223223
switch action {
224-
case .first: return .init(value: .second)
225-
case .second: return .none
224+
case .first:
225+
return .init(value: .second)
226+
case .second:
227+
state += 1
228+
return .none
226229
}
227230
}
228231
}

0 commit comments

Comments
 (0)