Skip to content

Using error in Contains fails with confusing message #828

@henrahmagix

Description

@henrahmagix

https://play.golang.org/p/u7Dfo4UnxZ0

assert.Contains(t, "error string", errors.New("error"))
Error Trace:	prog.go:25
Error:      	"error string" does not contain "error"
Test:       	TestCaseA

Whereas this is what's needed to pass:

-assert.Contains(t, "error string", errors.New("error"))
+assert.Contains(t, "error string", errors.New("error").Error())

I would prefer if the failure message explained that it was an error type, otherwise it looks like a string does not contain another string: I've fallen foul to this in the past, and just spent 5-10mins again not realising that I needed to pass a string type as the 3rd argument.

It would be really nice to have the type printed here when the value isn't a Stringer =)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions