πŸ‘©β€πŸ« toBeTruthy and toBeFalsy
Tell the truthy, or at least don't falsy.
These comparisons are used to determine if a value is truthy or falsy in the JavaScript sense. In JavaScript there are only six falsy values:
    false
    0
    ""
    null
    undefined
    NaN
In AssemblyScript, there is no undefined, so as-pect will treat each of those values as falsy. Truthy values are anything that is not falsy,
1
// true is truthy!
2
expect(true).toBeTruthy();
3
​
4
// a reference is always truthy, unless it's null
5
expect(new Vec3(1, 2, 3)).toBeTruthy();
6
​
7
// 1 is truthy
8
expect(1).toBeTruthy();
9
​
10
// strings with values are always truthy
11
expect("Something!").toBeTruthy();
12
​
13
// false is falsy
14
expect(false).toBeFalsy();
15
​
16
// null is falsy
17
expect<Vec3 | null>(null).toBeFalsy();
18
​
19
// 0 is falsy
20
expect(0).toBeFalsy();
21
​
22
// NaN is always falsy
23
expect(NaN).toBeFalsy();
24
​
25
// empty strings are falsy
26
expect("").toBeFalsy();
Copied!
These methods are safe to use with jest.
Last modified 1yr ago
Copy link