elm-explorations / test

Write unit and fuzz tests for Elm code.
https://package.elm-lang.org/packages/elm-explorations/test/latest
BSD 3-Clause "New" or "Revised" License
236 stars 40 forks source link

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

Open Janiczek opened 1 year ago

Janiczek commented 1 year ago

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