-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect require.Error() docs #1609
Comments
hello @andig is this the |
Thank you for the quick reply. Seems I was actually looking at // Error asserts that a function returned an error (i.e. not `nil`).
//
// actualObj, err := SomeFunction()
// if assert.Error(t, err) {
// assert.Equal(t, expectedError, err)
// }
func Error(t TestingT, err error, msgAndArgs ...interface{}) {
if h, ok := t.(tHelper); ok {
h.Helper()
}
if assert.Error(t, err, msgAndArgs...) {
return
}
t.FailNow()
} |
yea I think so, but I checked the docs for |
The doc-string for Error needs to be made into one which works for both the assert and require packages. Especially after #1610 is merged. I'd suggest simply removing the if statement and the Equal call from the example. Especially since EqualError exists. |
Hi @brackendawson, I can fix this doc-string for assert and require. To reconfirm we want to update the doc not to have an example that uses if block and then // Error asserts that a function returned an error (i.e. not `nil`).
//
// actualObj, err := SomeFunction()
// assert.Error(t, err)
func Error(t TestingT, err error, msgAndArgs ...interface{}) bool {
if err == nil {
if h, ok := t.(tHelper); ok {
h.Helper()
}
return Fail(t, "An error is expected but got nil.", msgAndArgs...)
}
return true
} and similar change in https://github.com/stretchr/testify/blob/master/require/require.go#L280 |
Yes. The change in require is automatic, just run |
@brackendawson, I have created pull request #1675, can you please help me with review on this. |
Description
The error docs read:
This indicates that
Error()
has abool
return value which it hasn't. There is no way to checkexpectedError
like this.Expected behavior
Error docs should show actual usage. It would be nice if
Error()
actually allowed for checking the specific error value.The text was updated successfully, but these errors were encountered: