diff --git a/WorkflowTesting/Sources/RenderTesterResult.swift b/WorkflowTesting/Sources/RenderTesterResult.swift index ab71c92e..b772b342 100644 --- a/WorkflowTesting/Sources/RenderTesterResult.swift +++ b/WorkflowTesting/Sources/RenderTesterResult.swift @@ -80,7 +80,13 @@ public struct RenderTesterResult { line: UInt = #line ) -> RenderTesterResult where ActionType.WorkflowType == WorkflowType, ActionType: Equatable { verifyAction(file: file, line: line) { appliedAction in - XCTAssertEqual(appliedAction, action, file: file, line: line) + XCTAssertNoDifference( + appliedAction, + action, + "Action (First) does not match expected action (Second)", + file: file, + line: line + ) } } @@ -120,7 +126,13 @@ extension RenderTesterResult where WorkflowType.State: Equatable { file: StaticString = #file, line: UInt = #line ) -> RenderTesterResult { - XCTAssertEqual(state, expectedState, file: file, line: line) + XCTAssertNoDifference( + state, + expectedState, + "State (First) does not match expected state (Second)", + file: file, + line: line + ) return self } @@ -137,9 +149,9 @@ extension RenderTesterResult where WorkflowType.State: Equatable { var initialState = initialState try modifications(&initialState) XCTAssertNoDifference( - initialState, state, - "Expected state does not match", + initialState, + "State (First) does not match expected state (Second)", file: file, line: line ) @@ -156,7 +168,13 @@ extension RenderTesterResult where WorkflowType.Output: Equatable { line: UInt = #line ) -> RenderTesterResult { verifyOutput(file: file, line: line) { output in - XCTAssertEqual(output, expectedOutput, file: file, line: line) + XCTAssertNoDifference( + output, + expectedOutput, + "Output (First) does not match expected output (Second)", + file: file, + line: line + ) } } } diff --git a/WorkflowTesting/Tests/WorkflowRenderTesterFailureTests.swift b/WorkflowTesting/Tests/WorkflowRenderTesterFailureTests.swift index bb69d577..f3bd39c4 100644 --- a/WorkflowTesting/Tests/WorkflowRenderTesterFailureTests.swift +++ b/WorkflowTesting/Tests/WorkflowRenderTesterFailureTests.swift @@ -227,7 +227,14 @@ final class WorkflowRenderTesterFailureTests: XCTestCase { rendering.doNoopAction(10) } - expectingFailure(#"("noop(10)") is not equal to ("noop(70)")"#) { + expectingFailure(""" + failed - XCTAssertNoDifference failed: … + + − TestAction.noop(10) + + TestAction.noop(70) + + (First: −, Second: +) - Action (First) does not match expected action (Second) + """) { result.assert(action: TestAction.noop(70)) } @@ -272,7 +279,14 @@ final class WorkflowRenderTesterFailureTests: XCTestCase { } } - expectingFailure(#"("sendOutput("second")") is not equal to ("noop(0)")"#) { + expectingFailure(""" + failed - XCTAssertNoDifference failed: … + + − TestAction.sendOutput("second") + + TestAction.noop(0) + + (First: −, Second: +) - Action (First) does not match expected action (Second) + """) { result.assert(action: TestAction.noop(0)) } @@ -296,7 +310,14 @@ final class WorkflowRenderTesterFailureTests: XCTestCase { rendering.doOutput("hello") } - expectingFailure(#"("string("hello")") is not equal to ("string("nope")")"#) { + expectingFailure(""" + failed - XCTAssertNoDifference failed: … + + − TestWorkflow.Output.string("hello") + + TestWorkflow.Output.string("nope") + + (First: −, Second: +) - Output (First) does not match expected output (Second) + """) { result.assert(output: .string("nope")) } @@ -341,12 +362,36 @@ final class WorkflowRenderTesterFailureTests: XCTestCase { } } + func test_assertState() { + let result = TestWorkflow() + .renderTester(initialState: .idle) + .render { _ in } + + expectingFailure(""" + failed - XCTAssertNoDifference failed: … + + − TestWorkflow.State.idle + + TestWorkflow.State.sideEffect(key: "nah") + + (First: −, Second: +) - State (First) does not match expected state (Second) + """) { + result.assert(state: TestWorkflow.State.sideEffect(key: "nah")) + } + } + func test_assertStateModifications() { let result = TestWorkflow() .renderTester(initialState: .idle) .render { _ in } - expectingFailure("Expected state does not match") { + expectingFailure(""" + XCTAssertNoDifference failed: … + + − TestWorkflow.State.idle + + TestWorkflow.State.sideEffect(key: "nah") + + (First: −, Second: +) - State (First) does not match expected state (Second) + """) { result.assertStateModifications { state in state = .sideEffect(key: "nah") }