Skip to content

assert: add PanicsWithErrorIs #1350

@jannisbaudisch

Description

@jannisbaudisch

I have some code that wraps a database error with fmt.Errorf() and panics it. Now I want to assert that this error is paniced.

The current method PanicsWithError only compares the error message, but does not use a error chain comparison.

Example:

func foo(source err) {
    panic(fmt.Errorf("Wrapping error %w", source))
}

func Test(t *testing.T) {
    expectedError := errors.New("some error")
    require.PanicsWithErrorIs(t, expectedError, func() { foo(expectedError) }) // This functionality is missing
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpkg-assertChange related to package testify/asserttype-errorIssue related to comparing values implementing the error interface

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions