Код: Выделить всё
enum BankAccountError: Error {
case invalidAmount(Double)
}
@Test func depositNegativeAmountThrowsError() {
let bankAccount = BankAccount(accountNumber: "1234", balance: 500)
#expect("Invalid amount.", performing: {
try bankAccount.deposit(amount: -100, depositType: .check)
}, throws: { error in
// how to make sure that error is of type BankAccountError.invalidAmount
})
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... -exception
Мобильная версия