Skip to content

Instantly share code, notes, and snippets.

@mantovanirian
Created March 28, 2020 05:53
Show Gist options
  • Save mantovanirian/bac910a0a2a2793d69a18df07fd6658b to your computer and use it in GitHub Desktop.
Save mantovanirian/bac910a0a2a2793d69a18df07fd6658b to your computer and use it in GitHub Desktop.
func testErrorAndThenSucceed() {
let divisor = DivisorMock()
let vm = ViewModel(divisor: divisor.divide)
vm.load()
// nah ini kan gagal hit pertama
// ini ga perlu dites kan?
vm.load()
//anggap func .start return Result<Double, Error>
XCTAssertThrowsError(try vm.start().get())
}
class DivisorMock {
private var calledCount = 0
func divide(val1: Int, val2: Int) throws -> Double {
calledCount += 1
if (calledCount % 2 == 0) {
throw NSError()
} else { return 2 }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment