Skip to content

A public function to modify the failure string of an Expectation #211

Open

Description

@Janiczek

ArchitectureTest has this helper:

{-| A nice custom failure message for a failing expectation.

Now if only there was a way to get rid of the "Given ..." :)

-}
customFailure : Expectation -> (String -> String) -> Expectation
customFailure expectation failureString =
    case Test.Runner.getFailureReason expectation of
        Nothing ->
            Expect.pass

        Just { description, reason } ->
            Test.Runner.Failure.Extra.format description reason
                |> failureString
                |> Expect.fail

to use the nicely-formatted failure string, but wrap it in some explanations of its own.

This helper might be useful to others as well? Maybe it could live in this library, perhaps as mapFailureReason or something similar

[1,2,3]
|> Expect.equalLists [3,2,1]
|> Expect.mapFailureReason explainInputs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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