# vitest/prefer-to-be-falsy

> Require `toBeFalsy()` instead of `toBe(false)`

`toBe(false)` only passes for `false` itself. If the code returns `undefined`, `null`, or `0` instead, the test fails, even though `if (!value)` treats them all the same. `toBeFalsy()` passes for any falsy value.

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

`--fix-suggestions` replaces the matcher with `toBeFalsy()`. `--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]
"vitest/prefer-to-be-falsy" = "error" # or "warn"
```

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

## Examples

Reported:

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

test("a new cart has no discount", () => {
  const cart = createCart();
  expect(cart.hasDiscount).toBe(false);
  expect(cart.isOpen).not.toEqual(false);
});
```

Not reported:

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

test("a new cart has no discount", () => {
  const cart = createCart();
  expect(cart.hasDiscount).toBeFalsy();
  expect(cart.isOpen).not.toBeFalsy();
});
```

## When not to use it

`toBe(false)` is the stricter check. If returning `undefined` or `0` instead of `false` would be a bug, keep it. `vitest/prefer-strict-boolean-matchers` is the opposite rule.
