STRUCT
WorkflowActionTester
¶
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:)
¶
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.
assertNoOutput(file:line:)
¶
Asserts that the action produced no output
- returns: A tester containing the current state and output.
verifyOutput(file:line:_:)
¶
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.
verifyState(_:)
¶
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.