Mocks the code under 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
// billing.test.ts
vi.mock("./billing");// 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.
- OWASP: Secure coding with AI
- vibecop detectors
- owner's code bar
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"
}
}
}
./billing, the module this test file is named after. The test no longer runs the code it claims to test.