Skip to content

Commit d9be59d

Browse files
authored
docs(prefer-strict-boolean-matchers): added documentation for the rule (#653)
1 parent e2365c4 commit d9be59d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ export default [
197197
| [prefer-mock-promise-shorthand](docs/rules/prefer-mock-promise-shorthand.md) | enforce mock resolved/rejected shorthands for promises | | 🌐 | 🔧 | | |
198198
| [prefer-snapshot-hint](docs/rules/prefer-snapshot-hint.md) | enforce including a hint with external snapshots | | 🌐 | | | |
199199
| [prefer-spy-on](docs/rules/prefer-spy-on.md) | enforce using `vi.spyOn` | | 🌐 | 🔧 | | |
200+
| [prefer-strict-boolean-matchers](docs/rules/prefer-strict-boolean-matchers.md) | enforce using `toBe(true)` and `toBe(false)` over matchers that coerce types to boolean | | 🌐 | 🔧 | | |
200201
| [prefer-strict-equal](docs/rules/prefer-strict-equal.md) | enforce strict equal over equal | | 🌐 | | 💡 | |
201202
| [prefer-to-be](docs/rules/prefer-to-be.md) | enforce using toBe() | | 🌐 | 🔧 | | |
202203
| [prefer-to-be-falsy](docs/rules/prefer-to-be-falsy.md) | enforce using toBeFalsy() | | 🌐 | 🔧 | | |
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Enforce using `toBe(true)` and `toBe(false)` over matchers that coerce types to boolean (`vitest/prefer-strict-boolean-matchers`)
2+
3+
⚠️ This rule _warns_ in the 🌐 `all` config.
4+
5+
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
6+
7+
<!-- end auto-generated rule header -->
8+
9+
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()`).
10+
11+
```js
12+
// bad
13+
expect(foo).toBeTruthy()
14+
expectTypeOf(foo).toBeTruthy()
15+
expect(foo).toBeFalsy()
16+
expectTypeOf(foo).toBeFalsy()
17+
18+
19+
// good
20+
expect(foo).toBe(true)
21+
expectTypeOf(foo).toBe(true)
22+
expect(foo).toBe(false)
23+
expectTypeOf(foo).toBe(false)
24+
```

0 commit comments

Comments
 (0)