Skip to content

Commit 5e4caa8

Browse files
authored
Improve expected action test store failure message (#1883)
* Improve expected action test store failure message We currently interpolate the action directly, which prints in a pretty crude format that becomes almost incomprehensible for deeply nested actions (common in "integration" tests). So let's leverage Custom Dump instead! * Bump
1 parent 6633248 commit 5e4caa8

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
lines changed

ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.resolved

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ let package = Package(
2222
.package(url: "https://github.com/pointfreeco/combine-schedulers", from: "0.8.0"),
2323
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "0.10.0"),
2424
.package(url: "https://github.com/apple/swift-collections", from: "1.0.2"),
25-
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "0.6.0"),
25+
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "0.7.0"),
2626
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "0.1.2"),
2727
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "0.4.1"),
2828
.package(url: "https://github.com/pointfreeco/swiftui-navigation", from: "0.6.0"),

Sources/ComposableArchitecture/TestStore.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,9 +1311,15 @@ extension TestStore where ScopedState: Equatable, Action: Equatable {
13111311
file: StaticString = #file,
13121312
line: UInt = #line
13131313
) {
1314+
var expectedActionDump = ""
1315+
customDump(expectedAction, to: &expectedActionDump, indent: 2)
13141316
self.receiveAction(
13151317
matching: { expectedAction == $0 },
1316-
failureMessage: #"Expected to receive an action "\#(expectedAction)", but didn't get one."#,
1318+
failureMessage: """
1319+
Expected to receive the following action, but didn't: …
1320+
1321+
\(expectedActionDump)
1322+
""",
13171323
unexpectedActionDescription: { receivedAction in
13181324
TaskResultDebugging.$emitRuntimeWarnings.withValue(false) {
13191325
diff(expectedAction, receivedAction, format: .proportional)
@@ -1768,14 +1774,14 @@ extension TestStore where ScopedState: Equatable {
17681774
}
17691775

17701776
if !actions.isEmpty {
1771-
var action = ""
1772-
customDump(actions, to: &action)
1777+
var actionsDump = ""
1778+
customDump(actions, to: &actionsDump)
17731779
XCTFailHelper(
17741780
"""
17751781
\(actions.count) received action\
17761782
\(actions.count == 1 ? " was" : "s were") skipped:
17771783
1778-
\(action)
1784+
\(actionsDump)
17791785
""",
17801786
file: file,
17811787
line: line

Tests/ComposableArchitectureTests/TestStoreFailureTests.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
The store received 1 unexpected action after this one: …
137137
138138
Unhandled actions: [
139-
[0]: TestStoreFailureTests.Action.second
139+
[0]: .second
140140
]
141141
"""
142142
}
@@ -200,7 +200,7 @@
200200
Must handle 1 received action before sending an action: …
201201
202202
Unhandled actions: [
203-
[0]: TestStoreFailureTests.Action.second
203+
[0]: .second
204204
]
205205
"""
206206
}
@@ -216,7 +216,11 @@
216216
XCTExpectFailure {
217217
store.receive(.action)
218218
} issueMatcher: { issue in
219-
issue.compactDescription == #"Expected to receive an action "action", but didn't get one."#
219+
issue.compactDescription == """
220+
Expected to receive the following action, but didn't: …
221+
222+
TestStoreFailureTests.Action.action
223+
"""
220224
}
221225
}
222226

0 commit comments

Comments
 (0)