redline
LowTests and CIweak-assertion

Weak assertion

Weak assertion. .toBeDefined() only checks that something exists, not that it is right.

This is how the comment reads inline, under the flagged line.

Why it matters

'It returned something' passes for wrong answers too. These assertions inflate coverage without catching regressions.

What to do

Assert the exact value or the property that matters.

Examples

Flagged
expect(user).toBeDefined();
Better
expect(user.email).toBe("a@b.co");

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(u).toBeDefined();
tests/test_a.py
def test_a():
    assert user is not None

Left alone

expect(u.id).toBe(3);

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": [
      "weak-assertion"
    ],
    "severity": {
      "weak-assertion": "medium"
    }
  }
}

Read the source or report a false positive.