# bun:test/require-to-throw-message

> Require `toThrow()` to say which error it expects

`toThrow()` without an argument passes for any error at all, including a `TypeError` from a typo in the code under test. The test stays green even though it never reached the check you meant to test. Pass part of the message, a regular expression, or the error class.

`.not.toThrow()` is allowed, because there's no error to describe.

{/* 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/require-to-throw-message" = "error" # or "warn"
```

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

## Examples

Reported:

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

test("rejects a negative amount", async () => {
  expect(() => withdraw(-5)).toThrow();
  expect(() => withdraw(-5)).toThrowError();
  await expect(transfer(-5)).rejects.toThrow();
});
```

Not reported:

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

test("rejects a negative amount", async () => {
  expect(() => withdraw(-5)).toThrow("amount must be positive");
  expect(() => withdraw(-5)).toThrow(RangeError);
  await expect(transfer(-5)).rejects.toThrow(/positive/);
});

test("accepts a positive amount", () => {
  expect(() => withdraw(5)).not.toThrow();
});
```
