diff --git a/wallet/wallet_test.go b/wallet/wallet_test.go index 2e26f58..cc66fa6 100644 --- a/wallet/wallet_test.go +++ b/wallet/wallet_test.go @@ -12,6 +12,14 @@ func TestWallet(t *testing.T) { } } + assertError := func(t testing.TB, err error) { + t.Helper() + + if err == nil { + t.Error("wanted an error but didn't get one") + } + } + t.Run("deposit", func(t *testing.T) { wallet := Wallet{} wallet.Deposit(10) @@ -28,10 +36,8 @@ func TestWallet(t *testing.T) { startingBalance := Bitcoin(20) wallet := Wallet{balance: startingBalance} err := wallet.Withdraw(100) - assertBalance(t, wallet, startingBalance) - if err == nil { - t.Error("wanted an error but didn't get one") - } + assertError(t, err) + assertBalance(t, wallet, startingBalance) }) }