Skip to content

Commit 082d9f1

Browse files
authored
[fix]: support nil output in RenderTester Publisher extension (#236)
### Issue - the `WorkflowCombine` `RenderTester` extensions didn't allow `nil` output ### Description - add a new method to support `nil` output and match the naming convention of analogous methods - deprecate old method - update tests addresses #235
1 parent 37fcb98 commit 082d9f1

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

WorkflowCombine/Testing/PublisherTesting.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ import XCTest
2323
@testable import WorkflowCombine
2424

2525
extension RenderTester {
26-
/// Expect a `Publisher`s.
26+
/// Expect a `Publisher`-based Workflow.
2727
///
2828
/// `PublisherWorkflow` is used to subscribe to `Publisher`s.
2929
///
3030
/// - Parameters:
31+
/// - publisher: Type of the Publisher-based Workflow to expect
3132
/// - producingOutput: An output that should be returned when this worker is requested, if any.
3233
/// - key: Key to expect this `Workflow` to be rendered with.
3334
public func expect<PublisherType: Publisher>(
3435
publisher: PublisherType.Type,
35-
output: PublisherType.Output,
36+
producingOutput output: PublisherType.Output? = nil,
3637
key: String = ""
3738
) -> RenderTester<WorkflowType> where PublisherType.Failure == Never {
3839
expectWorkflow(
@@ -43,6 +44,19 @@ extension RenderTester {
4344
assertions: { _ in }
4445
)
4546
}
47+
48+
@available(*, deprecated, renamed: "expect(publisher:producingOutput:key:)")
49+
public func expect<PublisherType: Publisher>(
50+
publisher: PublisherType.Type,
51+
output: PublisherType.Output,
52+
key: String = ""
53+
) -> RenderTester<WorkflowType> where PublisherType.Failure == Never {
54+
expect(
55+
publisher: publisher,
56+
producingOutput: output,
57+
key: key
58+
)
59+
}
4660
}
4761

4862
#endif

WorkflowCombine/TestingTests/PublisherTests.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,26 @@ class PublisherTests: XCTestCase {
1616
func testPublisherWorkflow() {
1717
TestWorkflow()
1818
.renderTester()
19-
.expect(publisher: Publishers.Sequence<[Int], Never>.self, output: 1, key: "123")
19+
.expect(
20+
publisher: Publishers.Sequence<[Int], Never>.self,
21+
producingOutput: 1,
22+
key: "123"
23+
)
2024
.render {}
2125
}
2226

27+
func test_publisher_no_output() {
28+
TestWorkflow()
29+
.renderTester()
30+
.expect(
31+
publisher: Publishers.Sequence<[Int], Never>.self,
32+
producingOutput: nil,
33+
key: "123"
34+
)
35+
.render {}
36+
.assertNoAction()
37+
}
38+
2339
struct TestWorkflow: Workflow {
2440
typealias State = Void
2541
typealias Rendering = Void

0 commit comments

Comments
 (0)