Created
March 28, 2020 05:53
-
-
Save mantovanirian/bac910a0a2a2793d69a18df07fd6658b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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