Skip to content

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

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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