I have created tableView with sections by RxDataSources.
ViewController
viewModel.sectionsObservable
.bindTo(tableView.rx.items(dataSource: viewModel.dataSource))
.disposed(by: disposeBag)
sectionsObservable emits the event when a new element is added to the array.
I would like to test if a proper element is on proper indexPath.
func testGettingTaskForIndexPath() {
let element = Element()
viewModel.addElement(element)
let fetchedElement = viewModel.getElement(at: IndexPath(row: 0, section: 0))
XCTAssertEqual(element, fetchedElement)
}
ViewModel
func getElement(at indexPath: IndexPath) -> Element {
return self.dataSource.sectionModels[indexPath.section].items[indexPath.row]
}
it works in the app, but tests fail. fatal error: Index out of range
It's all because of that asynchronous. How to test this case?
Aucun commentaire:
Enregistrer un commentaire