When PanicsWithError fails with a message different from the expected one, the message might not indicate very well what the error was, and what the string mismatch is exactly.
Since the assertion expects this to be an error and it checks on the error message only, it would suffice to replace the listing of entire "Panic value" with panicErr.Error().
When
PanicsWithError
fails with a message different from the expected one, the message might not indicate very well what the error was, and what the string mismatch is exactly.It does work in simple cases:
Fails with:
It does not indicate the actual error message in case the error message is not in the fields:
Fails with:
A real world example here is https://pkg.go.dev/text/template#ExecError.
Since the assertion expects this to be an error and it checks on the error message only, it would suffice to replace the listing of entire "Panic value" with
panicErr.Error()
.