๐Ÿ‘ฉโ€๐Ÿซ 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,

// true is truthy!
expect(true).toBeTruthy();

// a reference is always truthy, unless it's null
expect(new Vec3(1, 2, 3)).toBeTruthy();

// 1 is truthy
expect(1).toBeTruthy();

// strings with values are always truthy
expect("Something!").toBeTruthy();

// false is falsy
expect(false).toBeFalsy();

// null is falsy
expect<Vec3 | null>(null).toBeFalsy();

// 0 is falsy
expect(0).toBeFalsy();

// NaN is always falsy
expect(NaN).toBeFalsy();

// empty strings are falsy
expect("").toBeFalsy();

These methods are safe to use with jest.

Last updated