Skip to content

Latest commit

 

History

History
25 lines (18 loc) · 899 Bytes

File metadata and controls

25 lines (18 loc) · 899 Bytes

vitest/prefer-strict-boolean-matchers

📝 Enforce using toBe(true) and toBe(false) over matchers that coerce types to boolean.

⚠️ 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)