redline
LowTests and CImock-heavy

Mock

Mock. vi.mock replaces real code in this test. That seam is no longer tested.

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

Why it matters

Every mock is a place where the test checks your assumption about the other code instead of the code itself. Heavy mocking is how suites pass while production breaks.

What to do

Use the real implementation or an in-memory fake, and prefer one end-to-end check over many mocked units.

Examples

Flagged
vi.mock("./db");
Better
const db = createTestDb();

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

vi.mock("./db");
tests/test_a.py
def test_a(monkeypatch):
    monkeypatch.setattr(x, 'y', 1)
    assert x

Left alone

const db = createTestDb();

Research

Mocking the code under test, or mocking so much that the test checks only mocks. The test proves the mock setup, not the code.

Turn it off or change it

In a config file for the CLI, or in the API's rules field:

{
  "rules": {
    "disable": [
      "mock-heavy"
    ],
    "severity": {
      "mock-heavy": "medium"
    }
  }
}

Read the source or report a false positive.