close

no-mocks-import

Added in v0.7.2

Configuration

PresetConfigured Value
✅ rstestPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, rstestPlugin } from '@rslint/core';

export default defineConfig([
  rstestPlugin.configs.recommended,
  {
    rules: {
      'rstest/no-mocks-import': 'error',
    },
  },
]);

Rule Details

Disallows importing a manual mock directly from a __mocks__ directory. Tests should mock the original module path so Rstest controls which module instance is used.

The rule checks both import declarations and require() calls.

Incorrect

import userClient from './__mocks__/user-client';

Correct

rs.mock('./user-client');
import userClient from './user-client';