Skip to content

Commit e567ef1

Browse files
committed
♻️ (bitcoin-wallet):refactor with assertion
1 parent 2afcf67 commit e567ef1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pointers-and-errors/bitcoin-and-wallet_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ func TestWallet(t *testing.T) {
1414
}
1515
}
1616

17+
assertError := func(t testing.TB, err error) {
18+
t.Helper()
19+
if err == nil {
20+
t.Error("wanted an error but didn't get one")
21+
}
22+
}
23+
1724
t.Run("deposit", func(t *testing.T) {
1825
wallet := Wallet{}
1926

@@ -35,10 +42,8 @@ func TestWallet(t *testing.T) {
3542
wallet := Wallet{startingBalance}
3643
err := wallet.Withdraw(Bitcoin(100))
3744

45+
assertError(t, err)
3846
assertBalance(t, wallet, startingBalance)
3947

40-
if err == nil {
41-
t.Error("wanted an error but didn't get one")
42-
}
4348
})
4449
}

0 commit comments

Comments
 (0)