What is the difference between expect(something).toBe(true)
, expect(something).toBeTruthy()
and expect(something).toBeTrue()
?
Note
Disclamer: This is just a wild guess
I know everybody loves an easy-to-read list:
toBe()
- The returned value is the same as
toBeTrue()
- Checks if the returned value is true
toBeTruthy()
- Check if the value, when cast to a boolean, will be a truthy value
Truthy values are all values that aren't 0
, ''
(empty string), false
, null
, NaN
, undefined
or []
(empty array)*.
* Notice that when you run !![]
, it returns true
, but when you run [] == false
it also returns true
. It depends on how it is implemented. In other words: (!![]) === ([] == false)
On your example, toBe(true)
and toBeTrue()
will yield the same results.