# bun:test/prefer-to-be-truthy

> Require `toBeTruthy()` instead of `toBe(true)`

`toBe(true)` passes only for `true` itself. If the code returns `1`, a string, or an object instead, the test fails, even though `if (value)` treats them all the same. `toBeTruthy()` passes for any truthy value.

`toEqual(true)` and `toStrictEqual(true)` are reported too, with or without `.not`.

`--fix-suggestions` replaces the matcher with `toBeTruthy()`. `--fix` doesn't, because the new matcher accepts more values.

{/* 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-to-be-truthy" = "error" # or "warn"
```

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

## Examples

Reported:

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

test("an admin can delete posts", () => {
  const user = createUser({ role: "admin" });
  expect(user.canDelete).toBe(true);
  expect(user.isBanned).not.toEqual(true);
});
```

Not reported:

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

test("an admin can delete posts", () => {
  const user = createUser({ role: "admin" });
  expect(user.canDelete).toBeTruthy();
  expect(user.isBanned).not.toBeTruthy();
});
```

## When not to use it

`toBe(true)` is the stricter check. If returning `1` or a string instead of `true` would be a bug, keep it. `bun:test/prefer-strict-boolean-matchers` is the opposite rule.
