Test without an assertion
Test without an assertion. This test never asserts anything. It passes as long as nothing throws.
This is how the comment reads inline, under the flagged line.
Why it matters
A test with no assertion only checks that nothing throws. It stays green when the code returns the wrong answer.
What to do
Assert on the result, the state change, or the error you expect.
Examples
it("computes tax", () => {
computeTax(order);
});it("computes tax", () => {
expect(computeTax(order)).toBe(8.25);
});What it catches
It reads the shape of the code: functions, blocks, loops and calls. 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
it("works", () => {
run();
});
tests/test_a.py
def test_a():
run()
Left alone
it("works", () => {
expect(run()).toBe(1);
});
tests/test_a.py
def test_a():
with pytest.raises(ValueError):
run()
Research
Tests with no assertion, assertions that cannot fail, and weak checks (`toBeDefined()`, `is not None`). The test passes for almost any wrong answer.
Turn it off or change it
In a config file for the CLI, or in the API's rules field:
{
"rules": {
"disable": [
"no-assertion"
],
"severity": {
"no-assertion": "low"
}
}
}