Expects any error
Expects any error. The test passes on any error (.toThrow()), including the wrong one.
This is how the comment reads inline, under the flagged line.
Why it matters
toThrow() with no argument or pytest.raises(Exception) passes when the code fails for an unrelated reason, like a typo.
What to do
Assert the error type and message: toThrow(NotFoundError), pytest.raises(ValueError, match=...).
Examples
expect(() => parse(x)).toThrow();
expect(() => parse(x)).toThrow(/empty input/);
What it catches
It reads a pattern on each line, aware of strings and comments. Languages: TypeScript and JavaScript, Python. Scope: Test files only. These cases are the rule's own tests: the first set must be flagged and the second must not.
Flagged
expect(() => parse(x)).toThrow();
tests/test_a.py
def test_a():
with pytest.raises(Exception):
f()
Left alone
expect(() => parse(x)).toThrow(/empty/);
expect(() => parse(x)).not.toThrow();
Research
`pytest.raises(Exception)`, or `toThrow()` with no argument. The test passes on the wrong error.
Turn it off or change it
In a config file for the CLI, or in the API's rules field:
{
"rules": {
"disable": [
"broad-raises"
],
"severity": {
"broad-raises": "low"
}
}
}