diff --git a/assert/assertions.go b/assert/assertions.go index 4e91332bb..7aaa850a6 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -2100,6 +2100,9 @@ func ErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool { var expectedText string if target != nil { expectedText = target.Error() + if err == nil { + return Fail(t, fmt.Sprintf("Expected error %q but got nil.", expectedText), msgAndArgs...) + } } chain := buildErrorChainString(err) diff --git a/assert/assertions_test.go b/assert/assertions_test.go index 9f859fa8d..8f0a0a958 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -3237,13 +3237,10 @@ func TestErrorIs(t *testing.T) { "in chain: \"EOF\"\n", }, { - err: nil, - target: io.EOF, - result: false, - resultErrMsg: "" + - "Target error should be in err chain:\n" + - "expected: \"EOF\"\n" + - "in chain: \n", + err: nil, + target: io.EOF, + result: false, + resultErrMsg: "Expected error \"EOF\" but got nil.\n", }, { err: io.EOF,