Skip to content

Reintroduce Expect.true/false with a better API? #224

Open

Description

@Janiczek

Maybe we should make it easier to do this:

|> Expect.equal True
|> Expect.onFail "The URL should still be present in the final URL after running autolinksUrl"

by having something like

|> Expect.true { onFalse = "The URL ..." }

The previous maintainers' reasons for removing Expect.true was that it took away the spotlight from better solutions (Expect.equalLists, ...), but sometimes you just have to work with predicates. It's not always possible/practical to use the other helpers. Let's trust our users to understand when to use which solution?

Activity

  1. gampleman commented on Sep 6, 2023

    @gampleman
    Contributor

    💯

    Spitballing some ideas:

    Expect.predicate : (a -> Bool) -> (a -> String) -> a -> Expectation
    

    One issue I found making custom predicate based assertions is that to make the error message good you need to have a way of including whatever you computed into the error message, but given that you usually do this in pipelines, this becomes annoying.

    \someFuzz ->
       someFuzz 
          |> SystemUnderTest.performOperation
          |> TestUtils.assertProperty
          |> Expect.equal True
    

    to add nicer error message:

    \someFuzz ->
       let 
          resultingValue =
               someFuzz 
                   |> SystemUnderTest.performOperation
       in
       resultingValue
          |> TestUtils.assertProperty
          |> Expect.equal True
          |> Expect.onFail ("assertProperty failed because " ++ Debug.toString resultingValue ++ " had this specific issue")
    

    Perhaps this API could even be improved to:

    Expect.predicate : (a -> Bool) -> (String -> String) -> a -> Expectation
    

    Where elm-test calls Debug.toString for you, so that its easier to package up custom assertions into elm packages?

    \someFuzz ->
       someFuzz 
          |> SystemUnderTest.performOperation
          |> Expect.predicate TestUtils.assertProperty 
               (\repr -> 
                  "assertProperty failed because " ++ rear ++ " had this specific issue"
               )
    
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