title: Unit Testing UICollectionView.indexPath(for: UICollectionViewCell)
body: <p>I am trying to unit test this bit of code in a <code>ViewController</code></p>
  
  <pre><code>    func categoryTextEditedAt(_ cell: UICollectionViewCell, _ text: String) {
          guard let indexPath = self.collectionView.indexPath(for: cell), text != "" else {return}
  
          //Rest of the codes to be tested
      }
  </code></pre>
  
  <p>And in my Unit Test to test the above function is as follows: </p>
  
  <pre><code>    func testCategoryTextEditedAt() {
          sut.viewDidLoad()
          sut.collectionView.reloadData()
          let cell = sut.collectionView.dataSource?.collectionView(sut.collectionView, cellForItemAt: IndexPath(item: 0, section: 0))
          sut.categoryTextEditedAt(cell!, "testString")
      }
  </code></pre>
  
  <p>but I am keep getting 'nil' for the <code>indexPath</code> inside <code>categoryTextEditedAt(:)</code> function. As I debug, I found that inside <code>testCategoryTextEditedAt()</code> cell has a value but <code>self.collectionView.indexPath(for:cell)</code> keeps returning 'nil' for 'indexPath.'</p>
  
  <p>How can I go about this process? </p>