redline
HighTests and CItrivial-assertion

Assertion that can't fail

Assertion that can't fail. expect(true).toBe asserts a constant. It passes no matter what the code does.

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

Why it matters

expect(true).toBe(true) makes a test look green and covered while checking nothing. Models write these to make a failing test pass.

What to do

Assert on the result of the code under test.

Examples

Flagged
expect(true).toBe(true);
Better
expect(total(cart)).toBe(42);

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(true).toBe(true);
tests/test_a.py
def test_a():
    assert True

Left alone

expect(total).toBe(42);

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

Read the source or report a false positive.