# prefer-strict-boolean-matchers

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

- Source: vitest
- Technologies: Testing
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #1801 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `vitest/prefer-strict-boolean-matchers` | no | safe | package `@vitest/eslint-plugin` | [docs](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-strict-boolean-matchers.md) |
| Oxlint | `vitest/prefer-strict-boolean-matchers` | no | safe | plugin `vitest`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/vitest/prefer-strict-boolean-matchers.html) |

## Code examples

### Incorrect: the rule reports this

```js
expect(foo).toBeTruthy()
expectTypeOf(foo).toBeTruthy()
expect(foo).toBeFalsy()
expectTypeOf(foo).toBeFalsy()
```

### Correct: the rule accepts this

```js
expect(foo).toBe(true)
expectTypeOf(foo).toBe(true)
expect(foo).toBe(false)
expectTypeOf(foo).toBe(false)
```

Examples from the Oxlint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import vitest from "@vitest/eslint-plugin";

export default [
  {
    plugins: { vitest },
    rules: {
      "vitest/prefer-strict-boolean-matchers": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "vitest"
  ],
  "rules": {
    "vitest/prefer-strict-boolean-matchers": "error"
  }
}
```

## Related rules

- [vitest/prefer-snapshot-hint](https://lintradar.dev/rules/vitest/prefer-snapshot-hint.md): Enforce including a hint with external snapshots
- [vitest/prefer-to-be](https://lintradar.dev/rules/vitest/prefer-to-be.md): Enforce using toBe()
- [vitest/prefer-mock-return-shorthand](https://lintradar.dev/rules/vitest/prefer-mock-return-shorthand.md): Prefer mock return shorthands
- [vitest/prefer-to-be-falsy](https://lintradar.dev/rules/vitest/prefer-to-be-falsy.md): Enforce using toBeFalsy()
- [vitest/prefer-mock-promise-shorthand](https://lintradar.dev/rules/vitest/prefer-mock-promise-shorthand.md): Enforce mock resolved/rejected shorthands for promises
- [vitest/prefer-to-be-object](https://lintradar.dev/rules/vitest/prefer-to-be-object.md): Enforce using toBeObject()

---

Web page: https://lintradar.dev/rules/vitest/prefer-strict-boolean-matchers. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
