Skip to content

Commit

Permalink
[fix]: support nil output in RenderTester Publisher extension (#236)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
jamieQ authored Aug 10, 2023
1 parent 37fcb98 commit 082d9f1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
18 changes: 16 additions & 2 deletions WorkflowCombine/Testing/PublisherTesting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ 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<PublisherType: Publisher>(
publisher: PublisherType.Type,
output: PublisherType.Output,
producingOutput output: PublisherType.Output? = nil,
key: String = ""
) -> RenderTester<WorkflowType> where PublisherType.Failure == Never {
expectWorkflow(
Expand All @@ -43,6 +44,19 @@ extension RenderTester {
assertions: { _ in }
)
}

@available(*, deprecated, renamed: "expect(publisher:producingOutput:key:)")
public func expect<PublisherType: Publisher>(
publisher: PublisherType.Type,
output: PublisherType.Output,
key: String = ""
) -> RenderTester<WorkflowType> where PublisherType.Failure == Never {
expect(
publisher: publisher,
producingOutput: output,
key: key
)
}
}

#endif
18 changes: 17 additions & 1 deletion WorkflowCombine/TestingTests/PublisherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
producingOutput: 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
Expand Down

0 comments on commit 082d9f1

Please sign in to comment.