Skip to content

Files

Latest commit

 

History

History
21 lines (15 loc) · 526 Bytes

prefer-to-be-falsy.md

File metadata and controls

21 lines (15 loc) · 526 Bytes

Pattern: toBe(false) in test assertions

Issue: -

Description

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.

Examples

Example of incorrect code:

expect(foo).toBe(false);
expectTypeOf(foo).toBe(false);

Example of correct code:

expect(foo).toBeFalsy();
expectTypeOf(foo).toBeFalsy();