Skip to content

Hi, How can you stub closure value ? #65

Closed Answered by dafurman
jack-liukui asked this question in Q&A
Discussion options

You must be logged in to vote

You can use executeTestWithOnClosure, like this:

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

1234 nil Optional("injectedString")

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Matejkob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants