You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: WorkflowTesting/Sources/WorkflowActionTester.swift
+36-3Lines changed: 36 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,12 @@ import XCTest
21
21
@testableimport Workflow
22
22
23
23
extensionWorkflowAction{
24
-
/// Returns a state tester containing `self`.
24
+
/// Returns a `WorkflowActionTester` with the given state before the `WorkflowAction` has been applied to it.
25
+
///
26
+
/// - Parameters:
27
+
/// - state: The `WorkflowType.State` instance that specifies the state before the `WorkflowAction` has been applied.
28
+
/// - workflow: An optional `WorkflowType` instance to be used if the `WorkflowAction` needs to read workflow properties off of the `ApplyContext` parameter during action application. If this parameter is unspecified, attempts to access the `WorkflowType`'s properties will error in the testing runtime.
29
+
/// - Returns: An appropriately-configured `WorkflowActionTester`.
25
30
publicstaticfunc tester(
26
31
withState state:WorkflowType.State,
27
32
workflow:WorkflowType?=nil
@@ -70,6 +75,19 @@ extension WorkflowAction {
70
75
/// .assert(output: .finished)
71
76
/// .assert(state: .differentState)
72
77
/// ```
78
+
///
79
+
/// If the `Action` under test uses the runtime's `ApplyContext` to read values from the
80
+
/// current `Workflow` instance, then an instance of the `Workflow` with the expected
81
+
/// properties that will be read during `send(action:)` must be supplied like:
guardlet value = expectedValues.removeValue(forKey: keyPath)as?Valueelse{
213
-
fatalError("Attempted to read value \(keyPath asAnyKeyPath), when applying an action, but no value was present. Pass an instance of the Workflow to the ActionTester to enable this functionality.")
230
+
guard
231
+
// We have an expected value
232
+
let value = expectedValues.removeValue(forKey: keyPath),
233
+
// And it's the right type
234
+
let value = value as?Value
235
+
else{
236
+
// We're expecting a value of optional type. Error, but don't crash
237
+
// since we can just return nil.
238
+
ifValue.self is OptionalProtocol.Type{
239
+
reportIssue("Attempted to read value \(keyPath asAnyKeyPath), when applying an action, but no value was present. Pass an instance of the Workflow to the ActionTester to enable this functionality.")
240
+
returnAny?.none as!Value
241
+
}else{
242
+
fatalError("Attempted to read value \(keyPath asAnyKeyPath), when applying an action, but no value was present. Pass an instance of the Workflow to the ActionTester to enable this functionality.")
0 commit comments