Hi, How can you stub closure value ? #65
-
@Spyable
public protocol RepositorySubscriptionCheckoutProtocol {
func executeTest(
with dto: String,
on completion: @escaping (Int, Error?, String?) -> Void
)
} How do we stub |
Beta Was this translation helpful? Give feedback.
Answered by
dafurman
Nov 14, 2023
Replies: 1 comment
-
You can use spy.executeTestWithOnClosure = { dto, completion in
completion(0, nil, "injectedString") // provide the values here that you want the spy to deliver via your closure
} Ex: let spy = RepositorySubscriptionCheckoutProtocolSpy()
spy.executeTestWithOnClosure = { dto, completion in
completion(1234, nil, "injectedString")
}
// I'm simulating the trigger of this function from your main code
spy.executeTest(with: "", on: { num, err, str in
print(num, err, str)
}) prints
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Matejkob
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
executeTestWithOnClosure
, like this:Ex:
prints