Last active
May 6, 2021 15:45
-
-
Save giovani-pereira-ifood/af0571fbd4d2ed548285a3cba45139ed to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// On the view's code | |
func setupGestures() { | |
let tap = UITapGestureRecognizer(target: self, action: #selector(callDelegateTap)) | |
addGestureRecognizer(tap) | |
} | |
// On the test code | |
func test_tappingView_shouldCallDelegate() { | |
let sut = MyView() | |
let gesture = sut.gestureRecognizers?.first { $0 is UITapGestureRecognizer } | |
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: "") ?? "" | |
sut.perform(.init(stringLiteral: selectorString)) | |
XCTAssertTrue(delegateSpy.viewTappedCalled) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment