testify
testify copied to clipboard
Improve ErrorIs message when error is nil but an error was expected
Summary
This improves the UX of users of ErrorIs() in case the value nil is passed for err while an error was expected.
Changes
- added check if
err == nil && target != nil-> return a special error-string - updated relevant test case
Motivation
The error message when an error is expected but err is nil (a common occurence in the world of testing) could be more helpful, e.g.:
(before)
some_test.go:20:
Error Trace: /[...]/some_test.go:20
Error: Target error should be in err chain:
expected: "sample error message"
in chain:
vs
(after)
some_test.go:20:
Error Trace: /[...]/some_test.go:20
Error: Expected error "sample error message" but got nil.