Skip to content

Files

Latest commit

 

History

History
21 lines (15 loc) · 526 Bytes

prefer-to-be-truthy.md

File metadata and controls

21 lines (15 loc) · 526 Bytes

Pattern: toBe(true) in test assertions

Issue: -

Description

Using toBe(true) in test assertions is less flexible and may miss other truthy values like non-empty strings or objects. The toBeTruthy() assertion provides a more comprehensive check for any truthy value, making tests more robust.

Examples

Example of incorrect code:

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

Example of correct code:

expect(foo).toBeTruthy();
expectTypeOf(foo).toBeTruthy();