vhesener / Closures

Swifty closures for UIKit and Foundation
MIT License
1.74k stars 146 forks source link

Unit testing code coverage inside the closure #62

Closed EddieLukeAtmey closed 1 year ago

EddieLukeAtmey commented 1 year ago

Is there any way to write Unit Test that can cover the code inside the closure block?

For example, here's a block of code I'd like to cover. How can I trigger the textField closure?

Screen Shot 2022-12-09 at 15 21 37

EddieLukeAtmey commented 1 year ago

I've found a hack to solve this issue:

import Closures

let tfPhone = try XCTUnwrap(vc.value(forKey: "phoneTextField") as? UITextField)
let selTextChange = Selector("editingChangedWithSender:event:")
tfPhone.perform(selTextChange, with: tfPhone, with: UIEvent())