Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: Add NotErrorAs method to {assert|require} packages #1137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

titusjaka
Copy link

Summary

Add NotErrorAs methods to check that none of the errors in err's chain matches target.

Changes

  • add NotErrorAs and NotErrorAsf assertions to assert and require packages

Motivation

Sometimes, it's essential to check that error does not match an exact type.

func TestExample(t *testing.T) {
	err := errors.New("test error")

	var notFoundErr ErrNotFound
	assert.NotErrorAs(t, err, &notFoundErr)

	err = WrapNotFoundError(err)
	assert.ErrorAs(t, err, &notFoundErr)
}

Related issues

Closes #1066

@johanneswuerbach
Copy link

I was just searching for this function, to discover it is missing.

Maybe @boyan-soubachov could have a look? :-)

@Antonboom
Copy link

+1 for this PR.
and take a look to #1129

@dolmen dolmen added pkg-assert Change related to package testify/assert pkg-require Change related to package testify/require type-error Issue related to comparing values implementing the error interface labels Mar 7, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
pkg-assert Change related to package testify/assert pkg-require Change related to package testify/require type-error Issue related to comparing values implementing the error interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

testify {assert|require} packages seem to be missing NotErrorAs methods.
4 participants