diff --git a/WorkflowReactiveSwift/Testing/SignalProducerWorkflowTesting.swift b/WorkflowReactiveSwift/Testing/SignalProducerWorkflowTesting.swift index ab129c84a..e1c3932d0 100644 --- a/WorkflowReactiveSwift/Testing/SignalProducerWorkflowTesting.swift +++ b/WorkflowReactiveSwift/Testing/SignalProducerWorkflowTesting.swift @@ -21,36 +21,19 @@ import XCTest @testable import WorkflowReactiveSwift extension RenderTester { - /// Expect a `SignalProducer`. + /// Expect a `SignalProducer` with an optional output. /// /// `SignalProducerWorkflow` is used to subscribe to `SignalProducer`s and `Signal`s. /// /// ⚠️ N.B. If you are testing a case in which multiple `SignalProducerWorkflow`s are expected, **only one of them** may have a non-nil `producingOutput` parameter. /// /// - Parameters: + /// - outputType: The `OutputType` of the expected `SignalProducerWorkflow`. Typically this will be correctly inferred by the type system, but may need to be explicitly specified if particular optionality is desired. /// - 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 expectSignalProducer( - producingOutput output: OutputType? = nil, - key: String = "", - file: StaticString = #file, line: UInt = #line - ) -> RenderTester { - expectWorkflow( - type: SignalProducerWorkflow.self, - key: key, - producingRendering: (), - producingOutput: output, - assertions: { _ in } - ) - } - - /// Expect a `SignalProducer` with the specified `outputType` that produces no `Output`. - /// - /// - Parameters: - /// - outputType: The `OutputType` of the expected `SignalProducerWorkflow`. - /// - key: Key to expect this `Workflow` to be rendered with. - public func expectSignalProducer( - outputType: OutputType.Type, + outputType: OutputType.Type = OutputType.self, + producingOutput: OutputType? = nil, key: String = "", file: StaticString = #file, line: UInt = #line ) -> RenderTester { @@ -58,6 +41,7 @@ extension RenderTester { type: SignalProducerWorkflow.self, key: key, producingRendering: (), + producingOutput: producingOutput, assertions: { _ in } ) } diff --git a/WorkflowReactiveSwift/TestingTests/SignalProducerTests.swift b/WorkflowReactiveSwift/TestingTests/SignalProducerTests.swift index ddea52cc7..7f3e098da 100644 --- a/WorkflowReactiveSwift/TestingTests/SignalProducerTests.swift +++ b/WorkflowReactiveSwift/TestingTests/SignalProducerTests.swift @@ -50,6 +50,16 @@ class SignalProducerTests: XCTestCase { .render {} } + func test_signalProducerWorkflow_optionalOutput() { + OptionalOutputWorkflow() + .renderTester() + .expectSignalProducer( + outputType: Int?.self, // comment this out & test fails + producingOutput: nil as Int? + ) + .render {} + } + private struct TestWorkflow: Workflow { typealias State = Void typealias Rendering = Void @@ -64,4 +74,16 @@ class SignalProducerTests: XCTestCase { } } } + + private struct OptionalOutputWorkflow: Workflow { + typealias State = Void + typealias Rendering = Void + typealias Output = Int? + + func render(state: State, context: RenderContext) -> Rendering { + SignalProducer(value: Int?.some(1)) + .mapOutput { _ in AnyWorkflowAction.noAction } + .rendered(in: context) + } + } } diff --git a/WorkflowRxSwift/Testing/ObservableTesting.swift b/WorkflowRxSwift/Testing/ObservableTesting.swift index 4e66f4638..b35dd937a 100644 --- a/WorkflowRxSwift/Testing/ObservableTesting.swift +++ b/WorkflowRxSwift/Testing/ObservableTesting.swift @@ -24,9 +24,11 @@ extension RenderTester { /// Expect the given worker. It will be checked for `isEquivalent(to:)` with the requested worker. /// - Parameters: - /// - worker: The worker to be expected - /// - output: An output that should be returned when this worker is requested, if any. + /// - outputType: The `OutputType` of the expected `ObservableWorkflow`. + /// - 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 expectObservable( + outputType: OutputType.Type = OutputType.self, producingOutput output: OutputType? = nil, key: String = "", file: StaticString = #file, line: UInt = #line diff --git a/WorkflowRxSwift/TestingTests/ObservableTests.swift b/WorkflowRxSwift/TestingTests/ObservableTests.swift index f318d4a6d..08b957425 100644 --- a/WorkflowRxSwift/TestingTests/ObservableTests.swift +++ b/WorkflowRxSwift/TestingTests/ObservableTests.swift @@ -28,7 +28,18 @@ class ObservableTests: XCTestCase { .render {} } - struct TestWorkflow: Workflow { + func test_observableWorkflow_optionalOutputType() { + OptionalOutputWorkflow() + .renderTester() + .expectObservable( + outputType: Int?.self, // comment this out & test fails + producingOutput: nil as Int?, + key: "123" + ) + .render {} + } + + private struct TestWorkflow: Workflow { typealias State = Void typealias Rendering = Void @@ -38,4 +49,17 @@ class ObservableTests: XCTestCase { .running(in: context, key: "123") } } + + private struct OptionalOutputWorkflow: Workflow { + typealias State = Void + typealias Rendering = Void + typealias Output = Int? + + func render(state: State, context: RenderContext) -> Rendering { + Observable.from([1]) + .map { Int?.some($0) } + .mapOutput { _ in AnyWorkflowAction.noAction } + .rendered(in: context, key: "123") + } + } }