Test verbose Contains Fail message

If asserting an error contained in a string, includeElement will fail
but Contains will confusingly print both values as strings, which can
look like a testify problem instead of an assertion failure.
pull/579/head
Henry Blyth 2020-03-09 21:43:35 +00:00 committed by Boyan Soubachov
parent c12dcedf28
commit cb23521296
1 changed files with 12 additions and 0 deletions

View File

@ -592,6 +592,18 @@ func TestContains(t *testing.T) {
}
}
func TestContainsFailMessage(t *testing.T) {
mockT := new(mockTestingT)
Contains(mockT, "Hello World", errors.New("Hello"))
expectedFail := "\"Hello World\" does not contain &errors.errorString{s:\"Hello\"}"
actualFail := mockT.errorString()
if !strings.Contains(actualFail, expectedFail) {
t.Errorf("Contains failure should include %q but was %q", expectedFail, actualFail)
}
}
func TestNotContains(t *testing.T) {
mockT := new(testing.T)