Skip to content

Improve expected action test store failure message #1883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let package = Package(
.package(url: "https://github.com/pointfreeco/combine-schedulers", from: "0.8.0"),
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "0.10.0"),
.package(url: "https://github.com/apple/swift-collections", from: "1.0.2"),
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "0.6.0"),
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "0.7.0"),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "0.1.2"),
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "0.4.1"),
.package(url: "https://github.com/pointfreeco/swiftui-navigation", from: "0.6.0"),
Expand Down
14 changes: 10 additions & 4 deletions Sources/ComposableArchitecture/TestStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1311,9 +1311,15 @@ extension TestStore where ScopedState: Equatable, Action: Equatable {
file: StaticString = #file,
line: UInt = #line
) {
var expectedActionDump = ""
customDump(expectedAction, to: &expectedActionDump, indent: 2)
self.receiveAction(
matching: { expectedAction == $0 },
failureMessage: #"Expected to receive an action "\#(expectedAction)", but didn't get one."#,
failureMessage: """
Expected to receive the following action, but didn't: …

\(expectedActionDump)
""",
unexpectedActionDescription: { receivedAction in
TaskResultDebugging.$emitRuntimeWarnings.withValue(false) {
diff(expectedAction, receivedAction, format: .proportional)
Expand Down Expand Up @@ -1768,14 +1774,14 @@ extension TestStore where ScopedState: Equatable {
}

if !actions.isEmpty {
var action = ""
customDump(actions, to: &action)
var actionsDump = ""
customDump(actions, to: &actionsDump)
XCTFailHelper(
"""
\(actions.count) received action\
\(actions.count == 1 ? " was" : "s were") skipped:

\(action)
\(actionsDump)
""",
file: file,
line: line
Expand Down
10 changes: 7 additions & 3 deletions Tests/ComposableArchitectureTests/TestStoreFailureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
The store received 1 unexpected action after this one: …

Unhandled actions: [
[0]: TestStoreFailureTests.Action.second
[0]: .second
]
"""
}
Expand Down Expand Up @@ -200,7 +200,7 @@
Must handle 1 received action before sending an action: …

Unhandled actions: [
[0]: TestStoreFailureTests.Action.second
[0]: .second
]
"""
}
Expand All @@ -216,7 +216,11 @@
XCTExpectFailure {
store.receive(.action)
} issueMatcher: { issue in
issue.compactDescription == #"Expected to receive an action "action", but didn't get one."#
issue.compactDescription == """
Expected to receive the following action, but didn't: …

TestStoreFailureTests.Action.action
"""
}
}

Expand Down