Skip to content

STRUCT

WorkflowActionTester

public struct WorkflowActionTester<WorkflowType, Action> where Action: WorkflowAction, Action.WorkflowType == WorkflowType

Testing helper that chains action sending and state/output assertions to make tests easier to write.

MyWorkflow.Action
    .tester(withState: .firstState)
    .send(action: .exampleAction)
    .verifyOutput { output in
        XCTAssertEqual(.finished, output)
    }
    .verifyState { state in
        XCTAssertEqual(.differentState, state)
    }

Or to assert that an action produces no output:

MyWorkflow.Action
    .tester(withState: .firstState)
    .send(action: .actionProducingNoOutput)
    .assertNoOutput()
    .verifyState { state in
        XCTAssertEqual(.differentState, state)
    }

If your State or Output are Equatable, you can use the convenience assertion methods:

MyWorkflow.Action
    .tester(withState: .firstState)
    .send(action: .exampleAction)
    .assert(output: .finished)
    .assert(state: .differentState)

Methods

send(action:)

public func send(action: Action) -> WorkflowActionTester<WorkflowType, Action>

Sends an action to the reducer.

  • parameter action: The action to send.

  • returns: A new state tester containing the state and output (if any) after the update.

Parameters

Name Description
action The action to send.

assertNoOutput(file:line:)

public func assertNoOutput(
    file: StaticString = #file,
    line: UInt = #line
) -> WorkflowActionTester<WorkflowType, Action>

Asserts that the action produced no output

  • returns: A tester containing the current state and output.

verifyOutput(file:line:_:)

public func verifyOutput(
    file: StaticString = #file,
    line: UInt = #line,
    _ assertions: (WorkflowType.Output) throws -> Void
) rethrows -> WorkflowActionTester<WorkflowType, Action>

Invokes the given closure (which is intended to contain test assertions) with the produced output. If the previous action produced no output, the triggers a test failure and does not execute the closure.

  • parameter assertions: A closure that accepts a single output value.

  • returns: A tester containing the current state and output.

Parameters

Name Description
assertions A closure that accepts a single output value.

verifyState(_:)

public func verifyState(_ assertions: (WorkflowType.State) throws -> Void) rethrows -> WorkflowActionTester<WorkflowType, Action>

Invokes the given closure (which is intended to contain test assertions) with the current state.

  • parameter assertions: A closure that accepts a single state value.

  • returns: A tester containing the current state and output.

Parameters

Name Description
assertions A closure that accepts a single state value.