redline
HighTests and CImock-of-subject

Mocks the code under test

Mocks the code under test. Mocks ./billing, the module this test file is named after. The test no longer runs the code it claims to test.

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

Why it matters

When a test mocks the module it's named after, it tests the mock. It will pass while the real code is broken.

What to do

Mock only the edges (network, clock) or use real collaborators; never the subject itself.

Examples

Flagged
// billing.test.ts
vi.mock("./billing");
Better
// billing.test.ts
vi.mock("./payments-client");

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

src/billing.test.ts
vi.mock("./billing");
it("a", () => { expect(1).toBe(1); });
tests/test_billing.py
@patch('app.billing.charge')
def test_a(m):
    assert m

Left alone

src/billing.test.ts
vi.mock("./payments-client");
it("a", () => { expect(1).toBe(1); });

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-of-subject"
    ],
    "severity": {
      "mock-of-subject": "low"
    }
  }
}

Read the source or report a false positive.