From 8e54a8ccd4d884e523302c6936798e29bdeda804 Mon Sep 17 00:00:00 2001 From: jamieQ Date: Thu, 10 Aug 2023 11:18:05 -0500 Subject: [PATCH 1/2] [fix]: support nil output in RenderTester Publisher extension --- WorkflowCombine/Testing/PublisherTesting.swift | 15 ++++++++++++++- .../TestingTests/PublisherTests.swift | 18 +++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/WorkflowCombine/Testing/PublisherTesting.swift b/WorkflowCombine/Testing/PublisherTesting.swift index bfd3999d0..28b3404ce 100644 --- a/WorkflowCombine/Testing/PublisherTesting.swift +++ b/WorkflowCombine/Testing/PublisherTesting.swift @@ -32,7 +32,7 @@ extension RenderTester { /// - key: Key to expect this `Workflow` to be rendered with. public func expect( publisher: PublisherType.Type, - output: PublisherType.Output, + producingOutput output: PublisherType.Output? = nil, key: String = "" ) -> RenderTester where PublisherType.Failure == Never { expectWorkflow( @@ -43,6 +43,19 @@ extension RenderTester { assertions: { _ in } ) } + + @available(*, deprecated, renamed: "expect(publisher:producingOutput:key:)") + public func expect( + publisher: PublisherType.Type, + output: PublisherType.Output, + key: String = "" + ) -> RenderTester where PublisherType.Failure == Never { + expect( + publisher: publisher, + producingOutput: output, + key: key + ) + } } #endif diff --git a/WorkflowCombine/TestingTests/PublisherTests.swift b/WorkflowCombine/TestingTests/PublisherTests.swift index f7c2f4ed5..f51bc6055 100644 --- a/WorkflowCombine/TestingTests/PublisherTests.swift +++ b/WorkflowCombine/TestingTests/PublisherTests.swift @@ -16,10 +16,26 @@ class PublisherTests: XCTestCase { func testPublisherWorkflow() { TestWorkflow() .renderTester() - .expect(publisher: Publishers.Sequence<[Int], Never>.self, output: 1, key: "123") + .expect( + publisher: Publishers.Sequence<[Int], Never>.self, + output: 1, + key: "123" + ) .render {} } + func test_publisher_no_output() { + TestWorkflow() + .renderTester() + .expect( + publisher: Publishers.Sequence<[Int], Never>.self, + producingOutput: nil, + key: "123" + ) + .render {} + .assertNoAction() + } + struct TestWorkflow: Workflow { typealias State = Void typealias Rendering = Void From bf33b5d7576c05bd0625cc295f2fa6be2b24fbec Mon Sep 17 00:00:00 2001 From: jamieQ Date: Thu, 10 Aug 2023 11:24:59 -0500 Subject: [PATCH 2/2] cleanup --- WorkflowCombine/Testing/PublisherTesting.swift | 3 ++- WorkflowCombine/TestingTests/PublisherTests.swift | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/WorkflowCombine/Testing/PublisherTesting.swift b/WorkflowCombine/Testing/PublisherTesting.swift index 28b3404ce..30edfc6e6 100644 --- a/WorkflowCombine/Testing/PublisherTesting.swift +++ b/WorkflowCombine/Testing/PublisherTesting.swift @@ -23,11 +23,12 @@ import XCTest @testable import WorkflowCombine extension RenderTester { - /// Expect a `Publisher`s. + /// Expect a `Publisher`-based Workflow. /// /// `PublisherWorkflow` is used to subscribe to `Publisher`s. /// /// - Parameters: + /// - publisher: Type of the Publisher-based Workflow to expect /// - producingOutput: An output that should be returned when this worker is requested, if any. /// - key: Key to expect this `Workflow` to be rendered with. public func expect( diff --git a/WorkflowCombine/TestingTests/PublisherTests.swift b/WorkflowCombine/TestingTests/PublisherTests.swift index f51bc6055..fe27d2d33 100644 --- a/WorkflowCombine/TestingTests/PublisherTests.swift +++ b/WorkflowCombine/TestingTests/PublisherTests.swift @@ -18,7 +18,7 @@ class PublisherTests: XCTestCase { .renderTester() .expect( publisher: Publishers.Sequence<[Int], Never>.self, - output: 1, + producingOutput: 1, key: "123" ) .render {}