diff --git a/WorkflowCombine/Sources/PublisherWorkflow.swift b/WorkflowCombine/Sources/PublisherWorkflow.swift index d101589c3..8b8ccb143 100644 --- a/WorkflowCombine/Sources/PublisherWorkflow.swift +++ b/WorkflowCombine/Sources/PublisherWorkflow.swift @@ -20,15 +20,14 @@ import Combine import Foundation import Workflow -struct PublisherWorkflow: Workflow where WorkflowPublisher.Failure == Never { - typealias Output = WorkflowPublisher.Output +struct PublisherWorkflow: Workflow { typealias State = Void typealias Rendering = Void - let publisher: WorkflowPublisher + let publisher: AnyPublisher - init(publisher: WorkflowPublisher) { - self.publisher = publisher + init(publisher: WorkflowPublisher) where WorkflowPublisher.Failure == Never, WorkflowPublisher.Output == Output { + self.publisher = publisher.eraseToAnyPublisher() } func render(state: State, context: RenderContext) -> Rendering { diff --git a/WorkflowCombine/Testing/PublisherTesting.swift b/WorkflowCombine/Testing/PublisherTesting.swift index 9968b8997..1c0d80fdc 100644 --- a/WorkflowCombine/Testing/PublisherTesting.swift +++ b/WorkflowCombine/Testing/PublisherTesting.swift @@ -23,6 +23,26 @@ import XCTest @testable import WorkflowCombine extension RenderTester { + /// Expect a `Publisher`-based Workflow. + /// + /// `PublisherWorkflow` is used to subscribe to `Publisher`s. + /// + /// - Parameters: + /// - producingOutput: An output that will be returned when this worker is requested, if any. + /// - key: Key to expect this `Workflow` to be rendered with. + public func expectPublisher( + producingOutput output: Output? = nil, + key: String = "" + ) -> RenderTester { + expectWorkflow( + type: PublisherWorkflow.self, + key: key, + producingRendering: (), + producingOutput: output, + assertions: { _ in } + ) + } + /// Expect a `Publisher`-based Workflow. /// /// `PublisherWorkflow` is used to subscribe to `Publisher`s. @@ -31,13 +51,14 @@ extension RenderTester { /// - publisher: Type of the Publisher-based Workflow to expect /// - producingOutput: An output that will be returned when this worker is requested, if any. /// - key: Key to expect this `Workflow` to be rendered with. + @available(*, deprecated, message: "Use expectPublisher(producingOutput:key:) instead") public func expect( publisher: PublisherType.Type, producingOutput output: PublisherType.Output? = nil, key: String = "" ) -> RenderTester where PublisherType.Failure == Never { expectWorkflow( - type: PublisherWorkflow.self, + type: PublisherWorkflow.self, key: key, producingRendering: (), producingOutput: output, @@ -45,7 +66,7 @@ extension RenderTester { ) } - @available(*, deprecated, renamed: "expect(publisher:producingOutput:key:)") + @available(*, deprecated, message: "Use expectPublisher(producingOutput:key:) instead") public func expect( publisher: PublisherType.Type, output: PublisherType.Output, diff --git a/WorkflowCombine/TestingTests/PublisherTests.swift b/WorkflowCombine/TestingTests/PublisherTests.swift index fe27d2d33..dbe280cd8 100644 --- a/WorkflowCombine/TestingTests/PublisherTests.swift +++ b/WorkflowCombine/TestingTests/PublisherTests.swift @@ -22,6 +22,14 @@ class PublisherTests: XCTestCase { key: "123" ) .render {} + + TestWorkflow() + .renderTester() + .expectPublisher( + producingOutput: 1, + key: "123" + ) + .render {} } func test_publisher_no_output() { @@ -34,6 +42,15 @@ class PublisherTests: XCTestCase { ) .render {} .assertNoAction() + + TestWorkflow() + .renderTester() + .expectPublisher( + producingOutput: Int?.none, + key: "123" + ) + .render {} + .assertNoAction() } struct TestWorkflow: Workflow {