Open Janiczek opened 1 year ago
💯
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"
)
Maybe we should make it easier to do this:
by having something like
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?