> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# no-mocks-import

[Added in v0.5.2](https://github.com/web-infra-dev/rslint/releases/tag/v0.5.2)
## Configuration

| Preset                           | Configured Value |
| -------------------------------- | ---------------- |
| ✅ jestPlugin.configs.all         | `"error"`        |
| ✅ jestPlugin.configs.recommended | `"error"`        |


```ts title=rslint.config.ts
import { defineConfig, jestPlugin } from '@rslint/core';

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

## Rule Details

When using `jest.mock`, tests should import from the original module path (for example `./x`), not from `./__mocks__/x`. Importing directly from a `__mocks__` path can leave you with more than one instance of the mocked module that are not the same reference, which is easy to misread and can make assertions fail in surprising ways.

This rule reports `import` declarations and `require()` calls whose module specifier path contains a `__mocks__` segment.

Examples of **incorrect** code for this rule:

```typescript
import thing from './__mocks__/index';
require('./__mocks__/index');
```

Examples of **correct** code for this rule:

```typescript
import thing from 'thing';
require('thing');
```

## Original Documentation

- [eslint-plugin-jest: no-mocks-import](https://github.com/jest-community/eslint-plugin-jest/blob/v29.16.0/docs/rules/no-mocks-import.md)
- [Source code](https://github.com/jest-community/eslint-plugin-jest/blob/v29.16.0/src/rules/no-mocks-import.ts)
