Pattern: toBe(false)
in test assertions
Issue: -
Using toBe(false)
in test assertions is less expressive and may miss other falsy values like 0
, null
, or undefined
. The toBeFalsy()
assertion provides a more comprehensive check for any falsy value, making tests more robust.
Example of incorrect code:
expect(foo).toBe(false);
expectTypeOf(foo).toBe(false);
Example of correct code:
expect(foo).toBeFalsy();
expectTypeOf(foo).toBeFalsy();