@@ -21,29 +21,49 @@ import XCTest
21
21
@testable import WorkflowReactiveSwift
22
22
23
23
extension RenderTester {
24
- /// Expect the given worker. It will be checked for `isEquivalent(to:)` with the requested worker.
24
+ /// Mock the given worker's output, and assert that the workflow's worker `isEquivalent(to:)` the ` worker` .
25
25
///
26
26
/// - Parameters:
27
- /// - worker: The worker to be expected
28
- /// - producingOutput: An output that will be returned when this worker is requested, if any.
27
+ /// - worker: The worker that we expect was created by the workflow. Will be compared using
28
+ /// `isEquivalent(to:)` to assert that the workflow's worker matches.
29
+ /// - producingOutput: The output to be used instead of actually running the worker.
30
+ /// If the workflow never tries to run the worker, then this won't be used.
29
31
/// - key: Key to expect this `Workflow` to be rendered with.
32
+ @available ( * , deprecated, renamed: " mockWorker " , message: " This method's name & parameter names were unclear. It has been renamed to mockWorker. " )
30
33
public func expect< ExpectedWorkerType: Worker > (
31
34
worker: ExpectedWorkerType ,
32
35
producingOutput output: ExpectedWorkerType . Output ? = nil ,
33
36
key: String = " " ,
34
37
file: StaticString = #file, line: UInt = #line
38
+ ) -> RenderTester < WorkflowType > {
39
+ mockWorker ( expectedWorker: worker, mockingOutput: output, key: key, file: file, line: line)
40
+ }
41
+
42
+ /// Mock the given worker's output, and assert that the workflow's worker `isEquivalent(to:)` the `expectedWorker`.
43
+ ///
44
+ /// - Parameters:
45
+ /// - expectedWorker: The worker that we expect was created by the workflow. Will be compared using
46
+ /// `isEquivalent(to:)` to assert that the workflow's worker matches.
47
+ /// - mockingOutput: The output to be used instead of actually running the worker.
48
+ /// If the workflow never tries to run the worker, then this won't be used.
49
+ /// - key: Key to expect this `Workflow` to be rendered with.
50
+ public func mockWorker< ExpectedWorkerType: Worker > (
51
+ expectedWorker: ExpectedWorkerType ,
52
+ mockingOutput output: ExpectedWorkerType . Output ? = nil ,
53
+ key: String = " " ,
54
+ file: StaticString = #file, line: UInt = #line
35
55
) -> RenderTester < WorkflowType > {
36
56
expectWorkflow (
37
57
type: WorkerWorkflow< ExpectedWorkerType> . self ,
38
58
key: key,
39
59
producingRendering: ( ) ,
40
60
producingOutput: output,
41
61
assertions: { workflow in
42
- guard !workflow. worker. isEquivalent ( to: worker ) else {
62
+ guard !workflow. worker. isEquivalent ( to: expectedWorker ) else {
43
63
return
44
64
}
45
65
XCTFail (
46
- " Workers of type \( ExpectedWorkerType . self) not equivalent. Expected: \( worker ) . Got: \( workflow. worker) " ,
66
+ " Workers of type \( ExpectedWorkerType . self) not equivalent. Expected: \( expectedWorker ) . Got: \( workflow. worker) " ,
47
67
file: file,
48
68
line: line
49
69
)
0 commit comments