From f49e0f15a42f2899d18d8032a7f349d568cad5f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Ribeiro?= Date: Sun, 5 Jan 2020 12:08:17 -0300 Subject: [PATCH] Update assertError when expected value is nil (#299) --- maps.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/maps.md b/maps.md index 8c77513ac..0a9a4dd3f 100644 --- a/maps.md +++ b/maps.md @@ -368,9 +368,22 @@ func TestAdd(t *testing.T) { assertDefinition(t, dictionary, word, definition) }) } +... +func assertError(t *testing.T, got, want error) { + t.Helper() + if got != want { + t.Errorf("got %q want %q", got, want) + } + if got == nil { + if want == nil { + return + } + t.Fatal("expected to get an error.") + } +} ``` -For this test, we modified `Add` to return an error, which we are validating against a new error variable, `ErrWordExists`. We also modified the previous test to check for a `nil` error. +For this test, we modified `Add` to return an error, which we are validating against a new error variable, `ErrWordExists`. We also modified the previous test to check for a `nil` error, as well as the `assertError` function. ## Try to run test