Skip to content

[fix]: support nil output in RenderTester Publisher extension #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:)")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are a handful of uses in the monorepo that can be migrated to avoid this warning

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