# bun:test/prefer-strict-boolean-matchers

> Require `toBe(true)` and `toBe(false)` instead of `toBeTruthy()` and `toBeFalsy()`

`toBeTruthy()` passes for `1`, `"no"` and `{}`. `toBeFalsy()` passes for `0`, `""`, `null` and `undefined`. If a function should return a boolean and starts returning `undefined`, a test with `toBeFalsy()` still passes. `toBe(false)` fails.

`--fix-suggestions` rewrites the matcher. `--fix` doesn't, because a test that passed with a non-boolean value fails afterwards.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"bun:test/prefer-strict-boolean-matchers" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 2} */}
```ts
import { expect, test } from "bun:test";

test("checks the password", () => {
  expect(isValid("correct horse")).toBeTruthy();
  expect(isValid("")).toBeFalsy();
});
```

Not reported:

{/* good */}
```ts
import { expect, test } from "bun:test";

test("checks the password", () => {
  expect(isValid("correct horse")).toBe(true);
  expect(isValid("")).toBe(false);
});
```

`not.toBeTruthy()` is reported too. The rewrite is `toBe(false)`, not `not.toBe(true)`, which would pass for everything except `true`.

{/* bad */}
```ts
import { expect, test } from "bun:test";

test("rejects an empty password", () => {
  expect(isValid("")).not.toBeTruthy();
});
```

## When not to use it

Some tests only care that there's a value, like a match from `String.prototype.match()` or a non-empty string. In those tests, `toBeTruthy()` says what you mean.

`bun:test/prefer-to-be-truthy` and `bun:test/prefer-to-be-falsy` ask for the opposite. Don't turn them on together with this rule.
