How to write a testcase for this "success" scenario?
if ([tblView.delegate respondsToSelector:@selector(tableView:viewForHeaderInSection:)]) {
...
}else{
...
}
I have tried by creating the below mock delegate in swift:
class MockTableViewDelegate:NSObject, UITableViewDelegate {
@objc func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 30
}
// MARK: Delegates
@objc func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return UIView()
}
}
Code:
mockTableView.delegate=MockTableViewDelegate()
print("delegate===\(mockTableView.delegate)")
It prints nil. The same mockup I have tried for the datasource and it is returning the datasource obj. Why delegate is returning nil? and how to test this scenario?