Have an actual assertion against `true` and discourage the use of `truthy`
jkrems opened this issue · 4 comments
truthy
is a very dangerous convenience. There's a lot of values that are truthy
but not true
and a truthy
test basically just checks that it's anything. It's way too easy to write tests that "pass by accident" when using truthy.
I agree. The "pass by accident" issue is real.
Did you intend to say to use "equal" over "truthy"?
If possible equal
is better than either, yes. But for things like x > 10
or just a precalculated x
, expect
would still be better than truthy
. The following code is inspired by a testium issue: groupon/testium#144
truthy 'is visible', @browser.evaluate ->
throw new Error 'Something goes terribly wrong'
$('.missing-element').is(':visible') # actually returns false
The above passes because the result of a failing evaluate happens to be "truthy" - but not true
. expect
would have properly caught it.
Aaaactually I just saw that expect
does not check for equality with true but also only for "truthy". I'm going to change the title of this issue to "assertive should have a way to actually assert with a hard test against true".
I'd love if expect
would change to mean "argument is exactly true". Might require a major bump but I think it'd be worth it.
I love this idea. It also neatly addresses the somewhat embarrassing expect
function whose use I have been discouraging, while keeping it for some kind of assert
library easy porting compat, despite disliking how its fast-and-loose-ness made it impossible to use with the docstring arg all other assertive calls take.
Forcing it to take boolean true
alone solves everything. :-) Totally worth doing with a major bump.