Skip to content

Latest commit

 

History

History
24 lines (17 loc) · 897 Bytes

prefer-strict-boolean-matchers.md

File metadata and controls

24 lines (17 loc) · 897 Bytes

Enforce using toBe(true) and toBe(false) over matchers that coerce types to boolean (vitest/prefer-strict-boolean-matchers)

⚠️ This rule warns in the 🌐 all config.

🔧 This rule is automatically fixable by the --fix CLI option.

This rule enforces using toBe(true) and toBe(false), which only match if the value is the corresponding boolean value. This is unlike toBeTruthy(), which matches any truthy value, such as a non-zero number or a non-empty string (which are, conversely, matched by toBeFalsy()).

// bad
expect(foo).toBeTruthy()
expectTypeOf(foo).toBeTruthy()
expect(foo).toBeFalsy()
expectTypeOf(foo).toBeFalsy()


// good
expect(foo).toBe(true)
expectTypeOf(foo).toBe(true)
expect(foo).toBe(false)
expectTypeOf(foo).toBe(false)