Skip to content

Commit 89d60fc

Browse files
authored
Use swift-custom-dump for all comparisons in RenderTesterResult (#318)
This expands the usage of swift-custom-dump to improve test failure readability ## Checklist - [x] Unit Tests - [x] UI Tests - [x] Snapshot Tests (iOS only) - [x] I have made corresponding changes to the documentation
1 parent c9b5a6f commit 89d60fc

File tree

2 files changed

+72
-9
lines changed

2 files changed

+72
-9
lines changed

Diff for: WorkflowTesting/Sources/RenderTesterResult.swift

+23-5
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ public struct RenderTesterResult<WorkflowType: Workflow> {
8080
line: UInt = #line
8181
) -> RenderTesterResult<WorkflowType> where ActionType.WorkflowType == WorkflowType, ActionType: Equatable {
8282
verifyAction(file: file, line: line) { appliedAction in
83-
XCTAssertEqual(appliedAction, action, file: file, line: line)
83+
XCTAssertNoDifference(
84+
appliedAction,
85+
action,
86+
"Action (First) does not match the expected action (Second)",
87+
file: file,
88+
line: line
89+
)
8490
}
8591
}
8692

@@ -120,7 +126,13 @@ extension RenderTesterResult where WorkflowType.State: Equatable {
120126
file: StaticString = #file,
121127
line: UInt = #line
122128
) -> RenderTesterResult<WorkflowType> {
123-
XCTAssertEqual(state, expectedState, file: file, line: line)
129+
XCTAssertNoDifference(
130+
state,
131+
expectedState,
132+
"State (First) does not match the expected state (Second)",
133+
file: file,
134+
line: line
135+
)
124136
return self
125137
}
126138

@@ -137,9 +149,9 @@ extension RenderTesterResult where WorkflowType.State: Equatable {
137149
var initialState = initialState
138150
try modifications(&initialState)
139151
XCTAssertNoDifference(
140-
initialState,
141152
state,
142-
"Expected state does not match",
153+
initialState,
154+
"State (First) does not match the expected state (Second)",
143155
file: file,
144156
line: line
145157
)
@@ -156,7 +168,13 @@ extension RenderTesterResult where WorkflowType.Output: Equatable {
156168
line: UInt = #line
157169
) -> RenderTesterResult<WorkflowType> {
158170
verifyOutput(file: file, line: line) { output in
159-
XCTAssertEqual(output, expectedOutput, file: file, line: line)
171+
XCTAssertNoDifference(
172+
output,
173+
expectedOutput,
174+
"Output (First) does not match the expected output (Second)",
175+
file: file,
176+
line: line
177+
)
160178
}
161179
}
162180
}

Diff for: WorkflowTesting/Tests/WorkflowRenderTesterFailureTests.swift

+49-4
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,14 @@ final class WorkflowRenderTesterFailureTests: XCTestCase {
227227
rendering.doNoopAction(10)
228228
}
229229

230-
expectingFailure(#"("noop(10)") is not equal to ("noop(70)")"#) {
230+
expectingFailure("""
231+
failed - XCTAssertNoDifference failed: …
232+
233+
− TestAction.noop(10)
234+
+ TestAction.noop(70)
235+
236+
(First: −, Second: +) - Action (First) does not match the expected action (Second)
237+
""") {
231238
result.assert(action: TestAction.noop(70))
232239
}
233240

@@ -272,7 +279,14 @@ final class WorkflowRenderTesterFailureTests: XCTestCase {
272279
}
273280
}
274281

275-
expectingFailure(#"("sendOutput("second")") is not equal to ("noop(0)")"#) {
282+
expectingFailure("""
283+
failed - XCTAssertNoDifference failed: …
284+
285+
− TestAction.sendOutput("second")
286+
+ TestAction.noop(0)
287+
288+
(First: −, Second: +) - Action (First) does not match the expected action (Second)
289+
""") {
276290
result.assert(action: TestAction.noop(0))
277291
}
278292

@@ -296,7 +310,14 @@ final class WorkflowRenderTesterFailureTests: XCTestCase {
296310
rendering.doOutput("hello")
297311
}
298312

299-
expectingFailure(#"("string("hello")") is not equal to ("string("nope")")"#) {
313+
expectingFailure("""
314+
failed - XCTAssertNoDifference failed: …
315+
316+
− TestWorkflow.Output.string("hello")
317+
+ TestWorkflow.Output.string("nope")
318+
319+
(First: −, Second: +) - Output (First) does not match the expected output (Second)
320+
""") {
300321
result.assert(output: .string("nope"))
301322
}
302323

@@ -341,12 +362,36 @@ final class WorkflowRenderTesterFailureTests: XCTestCase {
341362
}
342363
}
343364

365+
func test_assertState() {
366+
let result = TestWorkflow()
367+
.renderTester(initialState: .idle)
368+
.render { _ in }
369+
370+
expectingFailure("""
371+
failed - XCTAssertNoDifference failed: …
372+
373+
− TestWorkflow.State.idle
374+
+ TestWorkflow.State.sideEffect(key: "nah")
375+
376+
(First: −, Second: +) - State (First) does not match the expected state (Second)
377+
""") {
378+
result.assert(state: TestWorkflow.State.sideEffect(key: "nah"))
379+
}
380+
}
381+
344382
func test_assertStateModifications() {
345383
let result = TestWorkflow()
346384
.renderTester(initialState: .idle)
347385
.render { _ in }
348386

349-
expectingFailure("Expected state does not match") {
387+
expectingFailure("""
388+
XCTAssertNoDifference failed: …
389+
390+
− TestWorkflow.State.idle
391+
+ TestWorkflow.State.sideEffect(key: "nah")
392+
393+
(First: −, Second: +) - State (First) does not match the expected state (Second)
394+
""") {
350395
result.assertStateModifications { state in
351396
state = .sideEffect(key: "nah")
352397
}

0 commit comments

Comments
 (0)