Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save giovani-pereira-ifood/a4933acd717d6e5b04e92cc465bfde39 to your computer and use it in GitHub Desktop.
Save giovani-pereira-ifood/a4933acd717d6e5b04e92cc465bfde39 to your computer and use it in GitHub Desktop.
// On the view's code
lazy var actionButton: UIButton = {
let button = UIButton()
button.addTarget(self, action: #selector(didTapActionButton), for: .touchUpInside)
return button
}()
// On the test code
func test_pressingActionButton_shouldCallDelegate() {
let button = view.actionButton
let action = button.actions(forTarget: sut, forControlEvent: .touchUpInside)?.first ?? ""
sut.performSelector(onMainThread: Selector(action), with: nil, waitUntilDone: true)
XCTAssertTrue(delegateSpy.actionCalled)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment