Skip to content

No Module Mocking

Error
small-rules/no-module-mocking

Disallow Vitest and Jest module mocking; tests must replace dependencies through real interfaces.

Rationale

Ported from dmmulroy/anti-slop. Module mocks make tests depend on import machinery instead of the dependency seam the production code actually owns. Use a real interface, service layer, or faithful in-memory implementation.

Diagnostic Messages

moduleMock
Replace module mocking with dependency injection through a real interface, service layer, or faithful test implementation.

Configuration

This rule does not accept options.

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/no-module-mocking": "error"
}
}

Examples

Vitest module mock
vi.mock('./user-store');
real test implementation
const store = new InMemoryUserStore();