jest/require-to-throw-message Correctness
✅ This rule is turned on by default.
What it does
This rule triggers a warning if toThrow()
or toThrowError()
is used without an error message.
Example
javascript
// invalid
test("all the things", async () => {
expect(() => a()).toThrow();
expect(() => a()).toThrowError();
await expect(a()).rejects.toThrow();
await expect(a()).rejects.toThrowError();
});
// valid
test("all the things", async () => {
expect(() => a()).toThrow("a");
expect(() => a()).toThrowError("a");
await expect(a()).rejects.toThrow("a");
await expect(a()).rejects.toThrowError("a");
});
How to use
To enable this rule in the CLI or using the config file, you can use:
bash
oxlint --deny jest/require-to-throw-message --jest-plugin
json
{
"plugins": ["jest"],
"rules": {
"jest/require-to-throw-message": "error"
}
}