Closed UltiRequiem closed 2 years ago
@UltiRequiem you can use assert
or assertEquals
so no need to add assertFalse
@UltiRequiem you can use
assert
orassertEquals
so no need to addassertFalse
I already listed both options on Describe alternatives you've considered
.
Despite that, an assertFalse
function would upgrade readability and other libraries include it.
Another library that has something similar is Ava.
https://github.com/avajs/ava/blob/main/docs/03-assertions.md#falseactual-message
This looks too trivial to include in std to me.
Is there any supportive opinions to this other than the above?
This looks too trivial to include in std to me.
Is there any supportive opinions to this other than the above?
I think the two strongest points are readability, and that other frameworks have it.
But I understand if it is not wanted here 😆
I don't have a strong opinion if this should be implemented or not.
However, it should be assertNot
in my opinion to match the existing convention set by other assertions e.g. assertEquals()
vs assertNotEquals()
.
@bartlomieju @kt3k can we make a call yet on if we want to include this or not? The reasons for including it seem valid to me and I know I (and many other developers) would use it even though it is trivial 😉
If there's prior art for such assertion I'm willing to squint my eyes and accept it.
Researched other languages and libraries. Some languages seem intentionally avoiding including it (Node, Ruby, Rust, etc), but many languages/libraries seem having assertFalse
or similar. Interestingly I couldn't find any example of assertNot
, which I personally think is worth considering.
assertFalse
assertTrue
and assertFalse
https://junit.org/junit5/docs/5.0.1/api/org/junit/jupiter/api/Assertions.html#assertFalse-boolean-assert.true
and assert.false
https://api.qunitjs.com/assert/false/assert
and assertFalse
https://kotlinlang.org/api/latest/kotlin.test/kotlin.test/assert-false.htmlassertTrue
and assertFalse
https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertFalseassert.True
and assert.False
https://pkg.go.dev/github.com/stretchr/testify/assert#FalseassertTrue
and assertFalse
https://phpunit.readthedocs.io/en/9.5/assertions.htmlassertFalse
assert()
and doesn't have negative version https://nodejs.org/api/assert.htmlassert
and doesn't have negative version https://docs.ruby-lang.org/en/2.1.0/Test/Unit/Assertions.htmlassert!
and doesn't have negative version https://doc.rust-lang.org/std/macro.assert.htmlassert_bool
(similar to assert_true) and doesn't have negative version https://gildor478.github.io/ounit/ounit2/OUnit2/index.html#val-assert_bool@kt3k That's very interesting 🤔 seems like a fairly even split.
I think assertFalse
makes sense for many of the other languages mentioned because they have much narrower definitions of what it means to be falsy.
In JS I think it is misleading because assertFalse(""); assertFalse(0); assertFalse(null); assertFalse(undefined); assertFalse(NaN);
would all pass.
I suggested assertNot
because it fits the pattern for inverse assertions in deno_std
but I think assertFalsy
would also make sense. This would match Jest which has expect.toBeFalsy
.
I think Jest also has toBeTrue
and toBeFalse
but these match only the literal values true
and false
.
@kt3k since there are more examples of support for this feature I think we can add it.
Closing because the feature was merged.
Is your feature request related to a problem? Please describe.
Currently, the testing module lacks a method to check if a value is False.
Describe the solution you'd like
Describe alternatives you've considered
With the solution shown before we could
Which I think is a lot more readable. Similar to 👇🏽 https://jestjs.io/docs/expect#tobefalsy https://github.com/avajs/ava/blob/main/docs/03-assertions.md#falseactual-message