Skip to content

Commit

Permalink
Merge pull request #21 from square/dhaval/hookupExpectedWorkflowAsser…
Browse files Browse the repository at this point in the history
…tions

Hookup ExpectedWorkflow Assertions
  • Loading branch information
dhavalshreyas committed Jun 29, 2020
2 parents ea99110 + 28c7a44 commit 2613126
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion WorkflowTesting/Sources/Internal/RenderExpectations.swift
Expand Up @@ -36,10 +36,12 @@
internal class ExpectedWorkflow<ExpectedWorkflowType: Workflow>: AnyExpectedWorkflow {
let rendering: ExpectedWorkflowType.Rendering
let output: ExpectedWorkflowType.Output?
let assertions: (ExpectedWorkflowType) -> Void

init(key: String, rendering: ExpectedWorkflowType.Rendering, output: ExpectedWorkflowType.Output?, file: StaticString, line: UInt) {
init(key: String, rendering: ExpectedWorkflowType.Rendering, output: ExpectedWorkflowType.Output?, assertions: @escaping (ExpectedWorkflowType) -> Void = { _ in }, file: StaticString, line: UInt) {
self.rendering = rendering
self.output = output
self.assertions = assertions
super.init(workflowType: ExpectedWorkflowType.self, key: key, file: file, line: line)
}
}
Expand Down
Expand Up @@ -74,6 +74,7 @@
if let output = expectedWorkflow.output {
apply(action: outputMap(output))
}
expectedWorkflow.assertions(workflow)
return expectedWorkflow.rendering
}

Expand Down
3 changes: 2 additions & 1 deletion WorkflowTesting/Sources/WorkflowRenderTester.swift
Expand Up @@ -154,7 +154,7 @@
producingRendering rendering: ExpectedWorkflowType.Rendering,
producingOutput output: ExpectedWorkflowType.Output? = nil,
file: StaticString = #file, line: UInt = #line,
assertions: (ExpectedWorkflowType) -> Void = { _ in }
assertions: @escaping (ExpectedWorkflowType) -> Void = { _ in }
) -> RenderTester<WorkflowType> {
return RenderTester(
workflow: workflow,
Expand All @@ -164,6 +164,7 @@
key: key,
rendering: rendering,
output: output,
assertions: assertions,
file: file,
line: line
)
Expand Down
12 changes: 12 additions & 0 deletions WorkflowTesting/Tests/WorkflowRenderTesterFailureTests.swift
Expand Up @@ -289,6 +289,18 @@ final class WorkflowRenderTesterFailureTests: XCTestCase {
}
}

func test_verifyWorkflow_assertion_fails() {
let tester = TestWorkflow()
.renderTester(initialState: .workflow(param: "", key: ""))
.expectWorkflow(type: TestChildWorkflow.self, key: "", producingRendering: "", producingOutput: nil) { workflow in
XCTFail("Workflow Assertion Fired")
}

expectingFailure("Workflow Assertion Fired") {
tester.render { _ in }
}
}

// MARK: State

func test_verifyState() {
Expand Down

0 comments on commit 2613126

Please sign in to comment.