Last active
June 11, 2021 13:44
-
-
Save giovani-pereira-ifood/9ace37f5da267bf972907e489ddf494f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension XCTestCase { | |
public func perform(event: UIControl.Event, from button: UIControl, target: NSObject, args: Any?) { | |
let action = button.actions(forTarget: target, forControlEvent: event)?.first ?? "" | |
target.performSelector(onMainThread: Selector(action), with: args, waitUntilDone: true) | |
} | |
public func performGestureRecognizer<T>(type: T.Type, on view: UIView) { | |
let gesture = view.gestureRecognizers?.first { $0 is T } | |
let target = (gesture?.value(forKey: "_targets") as? [NSObject])?.first | |
let selectorString = String(describing: target) | |
.components(separatedBy: ", ") | |
.first? | |
.replacingOccurrences(of: "(action=", with: "") | |
.replacingOccurrences(of: "Optional(", with: "") | |
?? "" | |
view.perform(.init(stringLiteral: selectorString)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment